|
@@ -105,17 +105,25 @@ func (op *Operations) NewSession() DBOperations {
|
|
|
}
|
|
|
|
|
|
func (op *Operations) AutoMigrate(tables ...Table) error {
|
|
|
- dbModels := make([]any, 0)
|
|
|
+ tx := op.processDB.Begin()
|
|
|
+
|
|
|
for _, table := range tables {
|
|
|
dbModel, err := table.ToDBModel()
|
|
|
if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- dbModels = append(dbModels, dbModel)
|
|
|
+ err = tx.Table(table.TableName).AutoMigrate(dbModel)
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return op.processDB.AutoMigrate(dbModels...)
|
|
|
+ tx.Commit()
|
|
|
+
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func (op *Operations) Table(name string, args ...any) DBOperations {
|