gastownhall/beads · error
dropping %s for the 0058 repair: %w
Error message
dropping %s for the 0058 repair: %w
What it means
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.
Source
Thrown at internal/storage/schema/wisp_dep_forward_repair.go:345
if hasIndex {
if _, err := db.ExecContext(ctx, "ALTER TABLE wisp_dependencies DROP INDEX idx_wisp_dep_type_target"); err != nil {
return fmt.Errorf("dropping idx_wisp_dep_type_target for the 0058 repair: %w", err)
}
}
for _, c := range wispDepFinalConstraints {
if !strings.HasPrefix(c.name, "fk_") {
continue
}
present, err := schemaConstraintExists(ctx, db, wispDepTable, c.name)
if err != nil {
return err
}
if !present {
continue
}
if _, err := db.ExecContext(ctx, "ALTER TABLE wisp_dependencies DROP FOREIGN KEY "+c.name); err != nil {
return fmt.Errorf("dropping %s for the 0058 repair: %w", c.name, err)
}
}
hasPK, err := schemaHasPrimaryKey(ctx, db, wispDepTable)
if err != nil {
return err
}
if hasPK {
if _, err := db.ExecContext(ctx, "ALTER TABLE wisp_dependencies DROP PRIMARY KEY"); err != nil {
return fmt.Errorf("dropping the wisp_dependencies primary key for the 0058 repair: %w", err)
}
}
hasGenerated, err := schemaColumnExists(ctx, db, wispDepTable, "depends_on_id")
if err != nil {
return err
}
if hasGenerated {View on GitHub (pinned to 71377f2769)
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.
Example fix
// before ALTER TABLE wisp_dependencies DROP FOREIGN KEY fk_wisp_dep_issue -- Error 1146/privilege denied // after: run as a user with ALTER and re-run repair GRANT ALTER ON beads.* TO 'bd'@'%'; -- then: bd (restart to resume guarded repair)
Defensive patterns
Strategy: try-catch
Validate before calling
rows, err := db.QueryContext(ctx, `SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'wisp_dependencies' AND CONSTRAINT_TYPE = 'FOREIGN KEY'`)
if err != nil { log.Fatalf("cannot list FK constraints (privileges?): %v", err) }
rows.Close() Try / catch
if err := repairWispDependenciesForwardShape(ctx, db); err != nil {
var mysqlErr *mysql.MySQLError
if errors.As(err, &mysqlErr) && mysqlErr.Number == 1146 { // unknown table/constraint mismatch
// verify constraint names via SHOW CREATE TABLE, then re-run
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: DB user without ALTER/REFERENCES privileges; constraint name differs between MySQL and Dolt metadata views; repair racing another migration; replica without schema-change rights.
Related errors
- pre-repair for migration %s: %w
- dropping idx_wisp_dep_type_target for the 0058 repair: %w
- dropping the wisp_dependencies primary key for the 0058 repa
- dropping wisp_dependencies.depends_on_id for the 0058 repair
- adding wisp_dependencies.id for the 0058 repair: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/60f2b94b10d03324.
Report an issue: GitHub.