From a211dc68169d03ecb2050b6a9e10cb3d4d1691e9 Mon Sep 17 00:00:00 2001 From: Alyx Holms Date: Mon, 30 Oct 2023 13:57:39 -0600 Subject: [PATCH] fix: stepwise was making new migrations on every restart (#179) This will prevent the stepwise migrator from adding additional entries for the same version --- cmd/api/src/database/migration/stepwise.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/api/src/database/migration/stepwise.go b/cmd/api/src/database/migration/stepwise.go index c512c54d3d..136caaf1e6 100644 --- a/cmd/api/src/database/migration/stepwise.go +++ b/cmd/api/src/database/migration/stepwise.go @@ -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 { @@ -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(¤tVersionMigration).Error + } else { + return nil } }