{"record":{"id":"dfe8e5cfe9f28d53","repo":"ory/hydra","slug":"problem-deleting-migration-version-s","errorCode":null,"errorMessage":"problem deleting migration version %s","messagePattern":"problem deleting migration version (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/popx/migrator.go","lineNumber":412,"sourceCode":"\t\t\t\terr := mi.Runner(mi, c)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn errors.WithStack(err)\n\t\t\t\t}\n\n\t\t\t\t// #nosec G201 - mtn is a system-wide const\n\t\t\t\tif err := c.RawQuery(fmt.Sprintf(\"DELETE FROM %s WHERE version = ?\", mtn), mi.Version).Exec(); err != nil {\n\t\t\t\t\treturn errors.Wrapf(err, \"problem deleting migration version %s. YOUR DATABASE MAY BE IN AN INCONSISTENT STATE! MANUAL INTERVENTION REQUIRED!\", mi.Version)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif err := mb.isolatedTransaction(ctx, \"down\", func(conn *pop.Connection) error {\n\t\t\t\t\terr := mi.Runner(mi, conn)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn errors.WithStack(err)\n\t\t\t\t\t}\n\n\t\t\t\t\t// #nosec G201 - mtn is a system-wide const\n\t\t\t\t\tif err := conn.RawQuery(fmt.Sprintf(\"DELETE FROM %s WHERE version = ?\", mtn), mi.Version).Exec(); err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"problem deleting migration version %s\", mi.Version)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn nil\n\t\t\t\t}); err != nil {\n\t\t\t\t\treturn errors.WithStack(err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tl.Infof(\"%s applied successfully\", mi.Name)\n\t\t\treverted++\n\t\t\tremainingSteps--\n\t\t}\n\t\treturn nil\n\t}))\n}\n\nfunc (mb *MigrationBox) createTransactionalMigrationTable(ctx context.Context, c *pop.Connection, l *logrusx.Logger) error {\n\tmtn := sanitizedMigrationTableName(c)","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/popx/migrator.go#L394-L430","documentation":"During a transactional Down migration, the rollback and the DELETE of the version row share one transaction; if the DELETE fails the whole transaction (including the rollback) is undone and this error is returned. The database remains consistent — the migration was simply not reverted.","triggerScenarios":"Calling Down for a transactional migration where DELETE FROM schema_migration fails inside the isolated transaction: unique/foreign-key issues, table missing, privileges, or connection loss mid-transaction.","commonSituations":"schema_migration dropped or locked by another process; revoked DELETE privileges; transient connection failures during long rollbacks.","solutions":["Inspect the wrapped cause for the underlying SQL error and fix it","Confirm schema_migration exists and the DB user has DELETE privileges","Re-run Down after the fix; transactional semantics guarantee no partial state"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var n int\nif err := db.QueryRow(\"SELECT COUNT(*) FROM schema_migration\").Scan(&n); err != nil {\n    return fmt.Errorf(\"tracking table unreadable before Down: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := box.Down(ctx, 1); err != nil {\n    if isTransient(err) {\n        time.Sleep(time.Second)\n        return box.Down(ctx, 1) // transactional: safe to retry, state is consistent\n    }\n    return err\n}","preventionTips":["Keep stable connectivity during rollback runs","Grant DELETE privileges on schema_migration","Do not lock or drop the tracking table while migrations run"],"tags":["database","migration","go"],"backgroundTag":"migration-version-delete-failed","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}