gastownhall/beads · error

checking dependencies.id primary key: %w

Error message

checking dependencies.id primary key: %w

What it means

Wraps a failure of `schemaColumnInPrimaryKey(ctx, db, "dependencies", "id")` — the information_schema introspection used to decide whether dependencies.id is already the primary key. This is a schema-inspection failure, not a data problem.

Source

Thrown at internal/storage/schema/migration_repairs.go:528

// ones already done -- MODIFY COLUMN restating an identical definition and
// re-adding an already-present PRIMARY KEY are otherwise either redundant or
// outright rejected as a duplicate key.
func ensureDependenciesIDPrimaryKey(ctx context.Context, db DBConn) error {
	var remainingNull int
	if err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM dependencies WHERE id IS NULL").Scan(&remainingNull); err != nil {
		return fmt.Errorf("counting unbackfilled dependencies.id rows for migration 0053: %w", err)
	}
	if remainingNull > 0 {
		// Fail with an actionable count now rather than let a subsequent
		// MODIFY COLUMN ... NOT NULL below abort with a generic "column
		// cannot be null" error, or silently key the table while leaving
		// NULL-id rows behind it.
		return fmt.Errorf("migration 0053: %d dependencies row(s) have no depends_on_issue_id/depends_on_wisp_id/depends_on_external target and cannot be assigned an id (ck_dep_one_target should prevent this); repair manually before retrying", remainingNull)
	}

	idIsPrimaryKey, err := schemaColumnInPrimaryKey(ctx, db, "dependencies", "id")
	if err != nil {
		return fmt.Errorf("checking dependencies.id primary key: %w", err)
	}
	if idIsPrimaryKey {
		return nil
	}

	if _, err := db.ExecContext(ctx, "ALTER TABLE dependencies MODIFY COLUMN id CHAR(36) NOT NULL"); err != nil {
		return fmt.Errorf("finalizing dependencies.id for migration 0053: %w", err)
	}

	hasAnyPrimaryKey, err := schemaHasPrimaryKey(ctx, db, "dependencies")
	if err != nil {
		return fmt.Errorf("checking dependencies for an existing primary key: %w", err)
	}
	if hasAnyPrimaryKey {
		// The #4690 drifted shape has dependencies keyed some other way (or
		// keyless): a table can carry only one PRIMARY KEY, so whatever is
		// there must go before id can become it. The uk_dep_* natural-identity
		// unique keys (0043) enforce the real uniqueness independently of

View on GitHub (pinned to 71377f2769)

Solutions

  1. Retry `bd` — the check is read-only and safe to rerun
  2. Resolve the wrapped %w cause (start the Dolt server, fix credentials)
  3. Confirm the account can read information_schema (grant PROCESS if needed)
  4. If the server is repeatedly dying, check Dolt logs/disk space before retrying

Example fix

// before: restricted user fails introspection
GRANT PROCESS ON *.* TO 'beads'@'localhost';
// after: rerun
bd ready
Defensive patterns

Strategy: retry

Validate before calling

bd dolt sql -q "SELECT COUNT(*) FROM information_schema.STATISTICS WHERE TABLE_NAME='dependencies' AND COLUMN_NAME='id'" || echo 'introspection unavailable'

Try / catch

if err := ensureSchema(ctx, db); err != nil {
    if strings.Contains(err.Error(), "checking dependencies.id primary key") && transient(err) {
        return retryWithBackoff(ensureSchema)
    }
    return err
}

Prevention

When it happens

Trigger: The 0053 repair calls schemaColumnInPrimaryKey during startup; the underlying query against information_schema (STATISTICS/TABLE_CONSTRAINTS) fails — server unreachable, information_schema access denied, or a driver-level error mid-query.

Common situations: Dolt server not running or crashed during upgrade; connecting with a restricted database user; transient connection drop in a long schema-repair pass.

Related errors


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