gastownhall/beads · error

dropping wisp_dependencies.depends_on_id for the 0058 repair

Error message

dropping wisp_dependencies.depends_on_id for the 0058 repair: %w

What it means

Wraps a failure when dropping the generated column wisp_dependencies.depends_on_id (`ALTER TABLE wisp_dependencies DROP COLUMN depends_on_id`) during legacy-shape teardown. schemaColumnExists confirmed the column exists, but the DROP failed, aborting the repair before the surrogate key step.

Source

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

	}

	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 {
		if _, err := db.ExecContext(ctx, "ALTER TABLE wisp_dependencies DROP COLUMN depends_on_id"); err != nil {
			return fmt.Errorf("dropping wisp_dependencies.depends_on_id for the 0058 repair: %w", err)
		}
	}
	return nil
}

// ensureWispDepSurrogateKey adds the final shape's id column and primary key.
//
// It is added BEFORE deduplication on purpose. The natural identity of a row
// here is (issue_id, target), and two rows identical in every column have no
// deterministic survivor -- created_at has second resolution and created_by and
// type commonly take defaults, so ordinary retry inserts reach that state. Once
// every row carries a distinct UUID a delete can pick MIN(id) deterministically.
// The final primary key being the UUID also means ADD PRIMARY KEY can never
// fail on duplicates, which is the state that made the previous designs fatal.
//
// A legacy store categorically has no id column: the original 0021 created the
// composite-keyed shape without one, and ignored/0005 -- the only migration that
// adds id to a legacy store -- drops the generated column in the same guarded

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check the wrapped cause (%w) and remove any leftover index/constraint still referencing depends_on_id.
  2. Re-run the full guarded repair so earlier drop steps complete in order.
  3. Grant ALTER/DROP to the migration user and retry with no concurrent writers.
  4. If Dolt blocks the drop, upgrade Dolt to a version supporting the column removal and re-run `bd`.

Example fix

// before: DROP COLUMN fails — leftover index from a crashed pass
// after: drop the leftover index, then resume
// ALTER TABLE wisp_dependencies DROP INDEX <leftover>;
if err := repairWispDependenciesForwardShape(ctx, db); err != nil {
    return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

// check for leftover indexes/constraints referencing depends_on_id before repair
rows, err := db.QueryContext(ctx, `SELECT INDEX_NAME FROM information_schema.STATISTICS WHERE TABLE_NAME = 'wisp_dependencies' AND COLUMN_NAME = 'depends_on_id'`)
if err != nil { log.Fatalf("cannot inspect depends_on_id usage: %v", err) }
rows.Close()

Try / catch

if err := repairWispDependenciesForwardShape(ctx, db); err != nil {
    if strings.Contains(err.Error(), "dropping wisp_dependencies.depends_on_id") {
        // drop leftover indexes/constraints on depends_on_id, then re-run the guarded repair
        return fmt.Errorf("clear depends_on_id dependents and re-run: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: dropWispDepLegacyShape finds depends_on_id present and the ALTER TABLE DROP COLUMN errors — column still used by an index/constraint not yet dropped, privilege denial, lock timeout, or Dolt refusing to drop a column backing existing data.

Common situations: Crashed prior repair left indexes/constraints referencing depends_on_id; user lacks ALTER; concurrent DML blocking the table; Dolt version with restricted generated-column handling.

Related errors


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