{"record":{"id":"60f2b94b10d03324","repo":"gastownhall/beads","slug":"dropping-s-for-the-0058-repair-w","errorCode":null,"errorMessage":"dropping %s for the 0058 repair: %w","messagePattern":"dropping (.+?) for the 0058 repair: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/wisp_dep_forward_repair.go","lineNumber":345,"sourceCode":"\tif hasIndex {\n\t\tif _, err := db.ExecContext(ctx, \"ALTER TABLE wisp_dependencies DROP INDEX idx_wisp_dep_type_target\"); err != nil {\n\t\t\treturn fmt.Errorf(\"dropping idx_wisp_dep_type_target for the 0058 repair: %w\", err)\n\t\t}\n\t}\n\n\tfor _, c := range wispDepFinalConstraints {\n\t\tif !strings.HasPrefix(c.name, \"fk_\") {\n\t\t\tcontinue\n\t\t}\n\t\tpresent, err := schemaConstraintExists(ctx, db, wispDepTable, c.name)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif !present {\n\t\t\tcontinue\n\t\t}\n\t\tif _, err := db.ExecContext(ctx, \"ALTER TABLE wisp_dependencies DROP FOREIGN KEY \"+c.name); err != nil {\n\t\t\treturn fmt.Errorf(\"dropping %s for the 0058 repair: %w\", c.name, err)\n\t\t}\n\t}\n\n\thasPK, err := schemaHasPrimaryKey(ctx, db, wispDepTable)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif hasPK {\n\t\tif _, err := db.ExecContext(ctx, \"ALTER TABLE wisp_dependencies DROP PRIMARY KEY\"); err != nil {\n\t\t\treturn fmt.Errorf(\"dropping the wisp_dependencies primary key for the 0058 repair: %w\", err)\n\t\t}\n\t}\n\n\thasGenerated, err := schemaColumnExists(ctx, db, wispDepTable, \"depends_on_id\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif hasGenerated {","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/wisp_dep_forward_repair.go#L327-L363","documentation":"Wraps a failure when dropping one of the legacy foreign keys (each fk_* constraint in wispDepFinalConstraints) via `ALTER TABLE wisp_dependencies DROP FOREIGN KEY <name>` during the 0058 legacy-shape teardown. The constraint was confirmed present but its removal failed, aborting the repair before the primary key and generated column are dropped.","triggerScenarios":"dropWispDepLegacyShape iterates wispDepFinalConstraints, schemaIndexExists/schemaColumnExists checks report the fk present, and the DROP FOREIGN KEY ALTER errors — privilege denial, unknown-constraint mismatch, lock timeout, or Dolt engine restriction.","commonSituations":"DB user without ALTER/REFERENCES privileges; constraint name differs between MySQL and Dolt metadata views; repair racing another migration; replica without schema-change rights.","solutions":["Read the wrapped cause (%w): access denied → grant ALTER; lock timeout → retry when no writers are active.","Re-run the repair: each step is guarded, so a crashed prior pass resumes cleanly.","Verify actual constraint names with SHOW CREATE TABLE wisp_dependencies and correct any metadata drift.","Run schema changes on the writable primary with sole ownership of the database."],"exampleFix":"// before\nALTER TABLE wisp_dependencies DROP FOREIGN KEY fk_wisp_dep_issue -- Error 1146/privilege denied\n// after: run as a user with ALTER and re-run repair\nGRANT ALTER ON beads.* TO 'bd'@'%';\n-- then: bd (restart to resume guarded repair)","handlingStrategy":"try-catch","validationCode":"rows, err := db.QueryContext(ctx, `SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'wisp_dependencies' AND CONSTRAINT_TYPE = 'FOREIGN KEY'`)\nif err != nil { log.Fatalf(\"cannot list FK constraints (privileges?): %v\", err) }\nrows.Close()","typeGuard":null,"tryCatchPattern":"if err := repairWispDependenciesForwardShape(ctx, db); err != nil {\n    var mysqlErr *mysql.MySQLError\n    if errors.As(err, &mysqlErr) && mysqlErr.Number == 1146 { // unknown table/constraint mismatch\n        // verify constraint names via SHOW CREATE TABLE, then re-run\n    }\n    return err\n}","preventionTips":["Grant ALTER and REFERENCES privileges to the migration user.","Run the repair as the sole writer on the database.","Use SHOW CREATE TABLE to confirm constraint names match what the repair expects.","Re-run the full guarded repair after any failure instead of partial manual DDL."],"tags":["database","schema-repair","migration","foreign-key","ddl"],"backgroundTag":"schema-migration-ddl-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}