-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add some logging around forced migration #2938
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ func (c *Config) Migrate(dataMigConf datamigration.Config) error { | |
migrationsTable := "" | ||
ctx := context.Background() | ||
|
||
l.Infof("Running db migrations from %q", migrationsPath) | ||
l.Info("Initializing DB migrations...") | ||
purl, err := addMigrationsTable(pgURL, migrationsTable) | ||
if err != nil { | ||
return errors.Wrap(err, "parse PG URL") | ||
|
@@ -63,9 +63,10 @@ func (c *Config) Migrate(dataMigConf datamigration.Config) error { | |
} | ||
|
||
if version < PreForceUpgradeMigration { | ||
l.Infof("Migrating schema version %v to %v...", version, PreForceUpgradeMigration) | ||
err = m.Migrate(PreForceUpgradeMigration) | ||
if err != nil && err != migrate.ErrNoChange { | ||
return errors.Wrap(err, "migration up to IAM-V2-force-upgrade failed") | ||
return errors.Wrapf(err, "migration up to version %v failed", PreForceUpgradeMigration) | ||
} | ||
} | ||
|
||
|
@@ -90,12 +91,13 @@ func (c *Config) Migrate(dataMigConf datamigration.Config) error { | |
if isOnV1 { | ||
if isDirty { // we've attempted to migrate and not finished | ||
// get IAM db in original, clean state to avoid conflicts | ||
l.Infof("Detected unfinished migration; resetting IAM DB to clean state") | ||
err = legacy.ResetIAMDb(ctx, db) | ||
if err != nil { | ||
return errors.Wrap(err, "reset IAM V2 database") | ||
return errors.Wrap(err, "reset database") | ||
} | ||
if err := dataMigConf.Reset(); err != nil { | ||
return errors.Wrap(err, "reset v2 data migrations") | ||
return errors.Wrap(err, "reset data migrations") | ||
} | ||
if version != 0 { | ||
migrateV1Policies = true | ||
|
@@ -106,33 +108,41 @@ func (c *Config) Migrate(dataMigConf datamigration.Config) error { | |
if err != nil { | ||
return errors.Wrapf(err, "failed to set IAM v2 migration_status to %s", constants_v2.EnumInProgress) | ||
} | ||
l.Info("Setting up IAM data basics...") | ||
err = legacy.MigrateToV2(ctx, db, migrateV1Policies) | ||
if err != nil { | ||
statusErr := legacy.RecordMigrationStatus(ctx, constants_v2.EnumFailed, db) | ||
if statusErr != nil { | ||
return errors.Wrapf(statusErr, "failed to set IAM v2 migration_status to %s:%s", constants_v2.EnumFailed, err.Error()) | ||
return errors.Wrapf(statusErr, "failed to set IAM migration_status to %s:%s", constants_v2.EnumFailed, err.Error()) | ||
} | ||
return errors.Wrap(err, "IAM v2 force-upgrade failed") | ||
return errors.Wrap(err, "IAM data basics failed") | ||
} | ||
err = legacy.RecordMigrationStatus(ctx, constants_v2.EnumSuccessful, db) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to set IAM v2 migration_status to %s", constants_v2.EnumSuccessful) | ||
return errors.Wrapf(err, "failed to set IAM migration_status to %s", constants_v2.EnumSuccessful) | ||
} | ||
} | ||
|
||
// idempotent | ||
l.Info("Checking for data migrations...") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😎 |
||
err = dataMigConf.Migrate() | ||
if err != nil { | ||
return errors.Wrap(err, "IAM data migrations failed") | ||
} | ||
|
||
// perform remaining migrations | ||
l.Infof("Checking for remaining schema migrations...") | ||
err = m.Up() | ||
if err != nil && err != migrate.ErrNoChange { | ||
return errors.Wrap(err, "migrations failed") | ||
} | ||
|
||
l.Infof("Completed db migrations") | ||
version, _, err = m.Version() | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get version post-migration") | ||
} | ||
|
||
l.Infof("DB initialization complete at version %v", version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought it would be a bonus to actually show the final migration level in the log, too. |
||
|
||
err = db.Close() | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review sentiment seemed to favor removing v1 and v2 references, so updated a few error messages in that regard.