Add filename to error message

This commit is contained in:
Nise Void 2019-10-28 13:01:29 +01:00
parent 0e43d5ed69
commit de9e7d9a41
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3

View File

@ -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)
}
}