gastownhall/beads · error

dropping idx_wisp_dep_type_target for the 0058 repair: %w

Error message

dropping idx_wisp_dep_type_target for the 0058 repair: %w

What it means

Wraps a failure when dropping the legacy index idx_wisp_dep_type_target from wisp_dependencies as part of removing the pre-0058 shape. The DROP INDEX DDL failed even though schemaIndexExists confirmed the index is present. Repair aborts before the final constraints are installed.

Source

Thrown at internal/storage/schema/wisp_dep_forward_repair.go:329

//
// The order is load-bearing in two places. idx_wisp_dep_type_target is indexed
// on depends_on_id and must go before the column. Every foreign key must go
// before DROP PRIMARY KEY, because the primary key is the only issue_id-leading
// index on this shape and fk_wisp_dep_issue holds it hostage:
//
//	Error 1553 (HY000): can't drop index 'PRIMARY': needed in foreign key
//	constraint fk_wisp_dep_issue
//
// Each drop is guarded on the live schema, so a resume after a crash mid-drop
// skips what is already gone rather than failing on a missing object.
func dropWispDepLegacyShape(ctx context.Context, db DBConn) error {
	hasIndex, err := schemaIndexExists(ctx, db, wispDepTable, "idx_wisp_dep_type_target")
	if err != nil {
		return err
	}
	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)
		}
	}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check the wrapped cause (%w): privilege errors → grant ALTER/DROP; lock errors → retry when idle.
  2. Verify no leftover FK still depends on the index; if a prior repair crashed, re-run the repair so FKs are dropped first (guarded steps).
  3. Manually verify with SHOW INDEX / SHOW CREATE TABLE, then re-run `bd` to resume the idempotent repair.
  4. If Dolt refuses the ALTER, check Dolt version compatibility with generated-column tables and upgrade the server.

Example fix

// before: ALTER fails because FK still uses the index after a crashed pass
// after: re-run full repair (guarded) or drop dependent FK first
if err := repairWispDependenciesForwardShape(ctx, db); err != nil {
    log.Fatalf("resume repair after verifying FK state: %v", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// verify index state and permissions before running the repair
_, err := db.ExecContext(ctx, "SHOW INDEX FROM wisp_dependencies WHERE Key_name = 'idx_wisp_dep_type_target'")
if err != nil { log.Fatalf("cannot inspect index metadata: %v", err) }
_, err = db.ExecContext(ctx, "SHOW CREATE TABLE wisp_dependencies")
if err != nil { log.Fatalf("migration user lacks metadata/ALTER rights: %v", err) }

Try / catch

if err := repairWispDependenciesForwardShape(ctx, db); err != nil {
    if strings.Contains(err.Error(), "dropping idx_wisp_dep_type_target") {
        // inspect SHOW CREATE TABLE for leftover FKs relying on the index
        return fmt.Errorf("repair blocked on legacy index; clear dependent FKs and re-run: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: dropWispDepLegacyShape executes `ALTER TABLE wisp_dependencies DROP INDEX idx_wisp_dep_type_target` and the ALTER fails — missing DROP/ALTER privilege, metadata mismatch, lock contention, or the index is implicitly required by a FK not yet dropped.

Common situations: DB user lacking ALTER privilege on the schema; upgrade run concurrently with another migration; a foreign key still referencing the index (drop order mismatch after partial repair); Dolt storage engine rejecting the ALTER mid-transaction.

Related errors


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