Skip to content

Commit

Permalink
fix: remove transaction for public migration
Browse files Browse the repository at this point in the history
  • Loading branch information
bartventer committed Jan 5, 2024
1 parent 34f4739 commit 14c74d1
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions drivers/postgres/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,17 @@ func (m *Migrator) CreateSchemaForTenant(tenant string) error {

// MigratePublicSchema migrates the public tables
func (m *Migrator) MigratePublicSchema() error {
return m.DB.Transaction(func(tx *gorm.DB) error {

if len(m.publicModels) == 0 {
return errors.New("no public tables to migrate")
}
fmt.Println("[multitenancy] ⏳ migrating public tables...")
if err := tx.
Scopes(withMigrationOption(multiMigrationOptionMigratePublicTables)).
AutoMigrate(m.publicModels...); err != nil {
return err
}
fmt.Println("[multitenancy] ✅ public tables migrated")
return nil
})
if len(m.publicModels) == 0 {
return errors.New("no public tables to migrate")
}
fmt.Println("[multitenancy] ⏳ migrating public tables...")
if err := m.DB.
Scopes(withMigrationOption(multiMigrationOptionMigratePublicTables)).
AutoMigrate(m.publicModels...); err != nil {
return err
}
fmt.Println("[multitenancy] ✅ public tables migrated")
return nil
}

// AutoMigrate migrates the tables based on the migration options.
Expand Down

0 comments on commit 14c74d1

Please sign in to comment.