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

  1. Read the wrapped cause (%w): access denied → grant ALTER; lock timeout → retry when no writers are active.
  2. Re-run the repair: each step is guarded, so a crashed prior pass resumes cleanly.
  3. Verify actual constraint names with SHOW CREATE TABLE wisp_dependencies and correct any metadata drift.
  4. 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

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


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/60f2b94b10d03324. Report an issue: GitHub.