use db.Transaction helper for migrations
This commit is contained in:
@@ -74,10 +74,10 @@ func (db *DB) Migrate(ctx MigrationContext) error {
|
|||||||
|
|
||||||
func construct(ctx MigrationContext, id string, f func(*gorm.DB, MigrationContext) error) *gormigrate.Migration {
|
func construct(ctx MigrationContext, id string, f func(*gorm.DB, MigrationContext) error) *gormigrate.Migration {
|
||||||
return constructNoTx(ctx, id, func(db *gorm.DB, ctx MigrationContext) error {
|
return constructNoTx(ctx, id, func(db *gorm.DB, ctx MigrationContext) error {
|
||||||
tx := db.Begin()
|
return db.Transaction(func(tx *gorm.DB) error {
|
||||||
defer tx.Commit()
|
|
||||||
return f(tx, ctx)
|
return f(tx, ctx)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func constructNoTx(ctx MigrationContext, id string, f func(*gorm.DB, MigrationContext) error) *gormigrate.Migration {
|
func constructNoTx(ctx MigrationContext, id string, f func(*gorm.DB, MigrationContext) error) *gormigrate.Migration {
|
||||||
|
|||||||
Reference in New Issue
Block a user