diff --git a/dialect.go b/dialect.go index edc2c35..1f21aa6 100644 --- a/dialect.go +++ b/dialect.go @@ -10,6 +10,7 @@ import ( type SQLDialect interface { createVersionTableSQL() string // sql string to create the db version table insertVersionSQL() string // sql string to insert the initial version table row + updateVersionSQL() string // sql string to update version dbVersionQuery(db *sql.DB) (*sql.Rows, error) } diff --git a/fix.go b/fix.go index abb9d19..caa9ff8 100644 --- a/fix.go +++ b/fix.go @@ -29,6 +29,12 @@ func Fix(db *sql.DB, dir string) error { version = last.Version + 1 } + // fix db table as well + tx, err := db.Begin() + if err != nil { + log.Fatal("db.Begin: ", err) + } + // fix filenames by replacing timestamps with sequential versions for _, tsm := range tsMigrations { oldPath := tsm.Source @@ -38,8 +44,13 @@ func Fix(db *sql.DB, dir string) error { return err } + if _, err := tx.Exec(GetDialect().updateVersionSQL(), version, tsm.Version); err != nil { + tx.Rollback() + return err + } + version++ } - return nil + return tx.Commit() }