Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prune non supported migrations #5466

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading