Add filename to error message
This commit is contained in:
parent
0e43d5ed69
commit
de9e7d9a41
11
migrate.go
11
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user