diff --git a/migrate.go b/migrate.go index dcc4b29..96bd542 100644 --- a/migrate.go +++ b/migrate.go @@ -67,19 +67,22 @@ func Migrate(db *sql.DB, version int, o Options, asset AssetFunc) error { } for i := v + 1; i <= version; i++ { - script, err := asset(fmt.Sprintf(o.AssetPrefix+fileFormat, i)) + fileName := fmt.Sprintf(o.AssetPrefix+fileFormat, i) + errorf := func(e error) error { return fmt.Errorf(`migration "%s" failed: %w`, fileName, e) } + + script, err := asset(fileName) if err != nil { - return ErrUpdatesMissing + return errorf(ErrUpdatesMissing) } _, err = tx.Exec(string(script)) if err != nil { - return err + return errorf(err) } _, err = tx.Exec(`INSERT INTO ` + o.TableName + ` VALUES (` + strconv.Itoa(i) + `)`) if err != nil { - return err + return errorf(err) } }