sqldb: fix dirty migration in v0.19.0-rc1

This commit is contained in:
Andras Banki-Horvath committed 2025-03-28 11:00:57 +01:00
1 parent dae212697d
commit 7e54682493
3 files changed
+56

No files matched your search

+30
View File
@@ -115,6 +115,12 @@ type MigrationExecutor interface {
// GetSchemaVersion returns the current schema version of the database.
GetSchemaVersion() (int, bool, error)
// SetSchemaVersion sets the schema version of the database.
//
// NOTE: This alters the internal database schema tracker. USE WITH
// CAUTION!!!
SetSchemaVersion(version int, dirty bool) error
}
var (
@@ -381,6 +387,30 @@ func ApplyMigrations(ctx context.Context, db *BaseDB,
"(dirty=%v) as base version", currentVersion, dirty)
}
// Due to an a migration issue in v0.19.0-rc1 we may be at version 2 and
// have a dirty schema due to failing migration 3. If this is indeed the
// case, we need to reset the dirty flag to be able to apply the fixed
// migration.
// NOTE: this could be removed as soon as we drop v0.19.0-beta.
if version == 2 {
schemaVersion, dirty, err := migrator.GetSchemaVersion()
if err != nil {
return err
}
if schemaVersion == 3 && dirty {
log.Warnf("Schema version %d is dirty. This is "+
"likely a consequence of a failed migration "+
"in v0.19.0-rc1. Attempting to recover by "+
"resetting the dirty flag", schemaVersion)
err = migrator.SetSchemaVersion(4, false)
if err != nil {
return err
}
}
}
for _, migration := range migrations {
if migration.Version <= currentVersion {
log.Infof("Skipping migration '%s' (version %d) as it "+