{"record":{"id":"441a37d346fdaa7d","repo":"gastownhall/beads","slug":"checking-dependencies-id-primary-key-w","errorCode":null,"errorMessage":"checking dependencies.id primary key: %w","messagePattern":"checking dependencies\\.id primary key: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/migration_repairs.go","lineNumber":528,"sourceCode":"// ones already done -- MODIFY COLUMN restating an identical definition and\n// re-adding an already-present PRIMARY KEY are otherwise either redundant or\n// outright rejected as a duplicate key.\nfunc ensureDependenciesIDPrimaryKey(ctx context.Context, db DBConn) error {\n\tvar remainingNull int\n\tif err := db.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dependencies WHERE id IS NULL\").Scan(&remainingNull); err != nil {\n\t\treturn fmt.Errorf(\"counting unbackfilled dependencies.id rows for migration 0053: %w\", err)\n\t}\n\tif remainingNull > 0 {\n\t\t// Fail with an actionable count now rather than let a subsequent\n\t\t// MODIFY COLUMN ... NOT NULL below abort with a generic \"column\n\t\t// cannot be null\" error, or silently key the table while leaving\n\t\t// NULL-id rows behind it.\n\t\treturn 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)\n\t}\n\n\tidIsPrimaryKey, err := schemaColumnInPrimaryKey(ctx, db, \"dependencies\", \"id\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"checking dependencies.id primary key: %w\", err)\n\t}\n\tif idIsPrimaryKey {\n\t\treturn nil\n\t}\n\n\tif _, err := db.ExecContext(ctx, \"ALTER TABLE dependencies MODIFY COLUMN id CHAR(36) NOT NULL\"); err != nil {\n\t\treturn fmt.Errorf(\"finalizing dependencies.id for migration 0053: %w\", err)\n\t}\n\n\thasAnyPrimaryKey, err := schemaHasPrimaryKey(ctx, db, \"dependencies\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"checking dependencies for an existing primary key: %w\", err)\n\t}\n\tif hasAnyPrimaryKey {\n\t\t// The #4690 drifted shape has dependencies keyed some other way (or\n\t\t// keyless): a table can carry only one PRIMARY KEY, so whatever is\n\t\t// there must go before id can become it. The uk_dep_* natural-identity\n\t\t// unique keys (0043) enforce the real uniqueness independently of","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/migration_repairs.go#L510-L546","documentation":"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.","triggerScenarios":"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.","commonSituations":"Dolt server not running or crashed during upgrade; connecting with a restricted database user; transient connection drop in a long schema-repair pass.","solutions":["Retry `bd` — the check is read-only and safe to rerun","Resolve the wrapped %w cause (start the Dolt server, fix credentials)","Confirm the account can read information_schema (grant PROCESS if needed)","If the server is repeatedly dying, check Dolt logs/disk space before retrying"],"exampleFix":"// before: restricted user fails introspection\nGRANT PROCESS ON *.* TO 'beads'@'localhost';\n// after: rerun\nbd ready","handlingStrategy":"retry","validationCode":"bd dolt sql -q \"SELECT COUNT(*) FROM information_schema.STATISTICS WHERE TABLE_NAME='dependencies' AND COLUMN_NAME='id'\" || echo 'introspection unavailable'","typeGuard":null,"tryCatchPattern":"if err := ensureSchema(ctx, db); err != nil {\n    if strings.Contains(err.Error(), \"checking dependencies.id primary key\") && transient(err) {\n        return retryWithBackoff(ensureSchema)\n    }\n    return err\n}","preventionTips":["Grant the bd user metadata access (PROCESS / information_schema reads)","Verify server reachability before running migrations","Avoid killing bd during multi-step schema repair","Check server logs when introspection fails repeatedly"],"tags":["database","migration","introspection","sql"],"backgroundTag":"schema-introspection-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}