Skip to content

Commit

Permalink
fix: stepwise was making new migrations on every restart (#179)
Browse files Browse the repository at this point in the history
This will prevent the stepwise migrator from adding additional entries for the same version
  • Loading branch information
superlinkx authored Oct 30, 2023
1 parent 9dd5959 commit a211dc6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/api/src/database/migration/stepwise.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func (s *Migrator) executeStepwiseMigrations() error {
}
}

currentVersionMigration := model.NewMigration(version.GetVersion())

if migrationFilenames, err := s.MigrationFilenames(); err != nil {
return err
} else if manifest, err := NewManifest(migrationFilenames); err != nil {
Expand All @@ -164,8 +166,9 @@ func (s *Migrator) executeStepwiseMigrations() error {
return fmt.Errorf("could not get latest migration: %w", err)
} else if err := s.ExecuteMigrations(manifest.After(lastMigration.Version())); err != nil {
return fmt.Errorf("could not execute migrations: %w", err)
} else {
currentVersionMigration := model.NewMigration(version.GetVersion())
} else if lastMigration != currentVersionMigration {
return s.db.Create(&currentVersionMigration).Error
} else {
return nil
}
}

0 comments on commit a211dc6

Please sign in to comment.