@@ -115,6 +115,12 @@ type MigrationExecutor interface {
115
115
116
116
// GetSchemaVersion returns the current schema version of the database.
117
117
GetSchemaVersion () (int , bool , error )
118
+
119
+ // SetSchemaVersion sets the schema version of the database.
120
+ //
121
+ // NOTE: This alters the internal database schema tracker. USE WITH
122
+ // CAUTION!!!
123
+ SetSchemaVersion (version int , dirty bool ) error
118
124
}
119
125
120
126
var (
@@ -381,6 +387,30 @@ func ApplyMigrations(ctx context.Context, db *BaseDB,
381
387
"(dirty=%v) as base version" , currentVersion , dirty )
382
388
}
383
389
390
+ // Due to an a migration issue in v0.19.0-rc1 we may be at version 2 and
391
+ // have a dirty schema due to failing migration 3. If this is indeed the
392
+ // case, we need to reset the dirty flag to be able to apply the fixed
393
+ // migration.
394
+ // NOTE: this could be removed as soon as we drop v0.19.0-beta.
395
+ if version == 2 {
396
+ schemaVersion , dirty , err := migrator .GetSchemaVersion ()
397
+ if err != nil {
398
+ return err
399
+ }
400
+
401
+ if schemaVersion == 3 && dirty {
402
+ log .Warnf ("Schema version %d is dirty. This is " +
403
+ "likely a consequence of a failed migration " +
404
+ "in v0.19.0-rc1. Attempting to recover by " +
405
+ "resetting the dirty flag" , schemaVersion )
406
+
407
+ err = migrator .SetSchemaVersion (4 , false )
408
+ if err != nil {
409
+ return err
410
+ }
411
+ }
412
+ }
413
+
384
414
for _ , migration := range migrations {
385
415
if migration .Version <= currentVersion {
386
416
log .Infof ("Skipping migration '%s' (version %d) as it " +
0 commit comments