Skip to content

Commit

Permalink
Prune non supported migrations (#5466)
Browse files Browse the repository at this point in the history
* Prune non-supported migrations

Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
  • Loading branch information
amartinezfayo authored Sep 4, 2024
1 parent 6cb89e8 commit 763ebe5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 101 deletions.
40 changes: 18 additions & 22 deletions pkg/server/datastore/sqlstore/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const (
// lastMinorReleaseSchemaVersion is the schema version supported by the
// last minor release. When the migrations are opportunistically pruned
// from the code after a minor release, this number should be updated.
lastMinorReleaseSchemaVersion = 21
lastMinorReleaseSchemaVersion = 23
)

// the current code version
Expand Down Expand Up @@ -465,13 +465,23 @@ func migrateVersion(tx *gorm.DB, currVersion int, log logrus.FieldLogger) (versi
// Place all migrations handled by the current minor release here. This
// list can be opportunistically pruned after every minor release but won't
// break things if it isn't.
switch currVersion {
case 21:
// TODO: remove this migration in 1.9.0
err = migrateToV22(tx)
case 22:
// TODO: remove this migration in 1.9.0
err = migrateToV23(tx)
//
// When adding a supported migration to version XX, add a case and the
// corresponding function. The case in the following switch statement will
// look like this:
//
// case XX:
// err = migrateToVXX(tx)
//
// And the migrateToVXX function will be like this:
// func migrateToVXX(tx *gorm.DB) error {
// if err := tx.AutoMigrate(&Foo{}, &Bar{}).Error; err != nil {
// return sqlError.Wrap(err)
// }
// return nil
// }
//
switch currVersion { //nolint: gocritic // No upgrade required yet, keeping switch for future additions
default:
err = sqlError.New("no migration support for unknown schema version %d", currVersion)
}
Expand All @@ -482,20 +492,6 @@ func migrateVersion(tx *gorm.DB, currVersion int, log logrus.FieldLogger) (versi
return nextVersion, nil
}

func migrateToV22(tx *gorm.DB) error {
if err := tx.AutoMigrate(&RegisteredEntryEvent{}, &AttestedNodeEvent{}).Error; err != nil {
return sqlError.Wrap(err)
}
return nil
}

func migrateToV23(tx *gorm.DB) error {
if err := tx.AutoMigrate(&CAJournal{}).Error; err != nil {
return sqlError.Wrap(err)
}
return nil
}

func addFederatedRegistrationEntriesRegisteredEntryIDIndex(tx *gorm.DB) error {
// GORM creates the federated_registration_entries implicitly with a primary
// key tuple (bundle_id, registered_entry_id). Unfortunately, MySQL5 does
Expand Down
Loading

0 comments on commit 763ebe5

Please sign in to comment.