Skip to content

Commit

Permalink
fix(migrate): if migration exists in database reuse to update (#4191)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored and sguiheux committed Apr 17, 2019
1 parent 79043ec commit e91a5d1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions engine/api/migrate/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"strings"
"time"

"github.com/go-gorp/gorp"

"github.com/blang/semver"
"github.com/go-gorp/gorp"

"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/log"
Expand Down Expand Up @@ -39,9 +38,7 @@ func Run(ctx context.Context, db gorp.SqlExecutor, panicDump func(s string) (io.
for _, migration := range migrations {
func(currentMigration sdk.Migration) {
sdk.GoRoutine(ctx, "migrate_"+migration.Name, func(contex context.Context) {
var mig *sdk.Migration
var errMig error
mig, errMig = GetByName(db, currentMigration.Name)
mig, errMig := GetByName(db, currentMigration.Name)
if errMig != nil {
log.Error("Cannot get migration %s : %v", currentMigration.Name, errMig)
return
Expand All @@ -51,6 +48,9 @@ func Run(ctx context.Context, db gorp.SqlExecutor, panicDump func(s string) (io.
log.Info("Migration> %s> Already done (status: %s)", currentMigration.Name, mig.Status)
return
}

// set the previous migration id for for the case where the migration was reset
currentMigration.ID = mig.ID
} else {
currentMigration.Progress = "Begin"
currentMigration.Status = sdk.MigrationStatusInProgress
Expand All @@ -59,6 +59,7 @@ func Run(ctx context.Context, db gorp.SqlExecutor, panicDump func(s string) (io.
return
}
}

log.Info("Migration [%s]: begin", currentMigration.Name)
if err := currentMigration.ExecFunc(contex); err != nil {
log.Error("migration %s in ERROR : %v", currentMigration.Name, err)
Expand Down

0 comments on commit e91a5d1

Please sign in to comment.