{"record":{"id":"27d0ef8d117a4aaf","repo":"gastownhall/beads","slug":"check-s-s-w","errorCode":null,"errorMessage":"check %s.%s: %w","messagePattern":"check (.+?)\\.(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/clone_local_fks.go","lineNumber":89,"sourceCode":"\tfor _, fk := range CloneLocalFKs {\n\t\tvar tables int\n\t\tif err := db.QueryRow(\n\t\t\t`SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?`,\n\t\t\tfk.Table,\n\t\t).Scan(&tables); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"check %s exists: %w\", fk.Table, err)\n\t\t}\n\t\tif tables == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar constraints int\n\t\tif err := db.QueryRow(\n\t\t\t`SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS\n\t\t\t WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND CONSTRAINT_NAME = ? AND CONSTRAINT_TYPE = 'FOREIGN KEY'`,\n\t\t\tfk.Table, fk.Constraint,\n\t\t).Scan(&constraints); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"check %s.%s: %w\", fk.Table, fk.Constraint, err)\n\t\t}\n\t\tif constraints > 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar orphans int\n\t\t//nolint:gosec // G201: identifiers come from the fixed CloneLocalFKs spec above, not user input.\n\t\torphanCount := fmt.Sprintf(\n\t\t\t`SELECT COUNT(*) FROM %s t WHERE t.%s IS NOT NULL AND NOT EXISTS (SELECT 1 FROM %s r WHERE r.%s = t.%s)`,\n\t\t\tfk.Table, fk.Column, fk.RefTable, fk.RefColumn, fk.Column,\n\t\t)\n\t\tif err := db.QueryRow(orphanCount).Scan(&orphans); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"count %s orphans: %w\", fk.Table, err)\n\t\t}\n\n\t\tsevered = append(severed, SeveredCloneLocalFK{CloneLocalFK: fk, Orphans: orphans})\n\t}\n\treturn severed, nil","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/clone_local_fks.go#L71-L107","documentation":"While scanning for severed clone-local foreign keys, scanSeveredCloneLocalFKs queries information_schema.TABLE_CONSTRAINTS to see if a constraint already exists. A missing constraint is normal (that's what the repair fixes), but a query failure — wrapped here as `check %s.%s` — aborts the whole scan.","triggerScenarios":"The information_schema.TABLE_CONSTRAINTS COUNT(*) query in scanSeveredCloneLocalFKs (cmd/bd/doctor/fix/clone_local_fks.go:89) returns a driver error, e.g. during ScanSeveredCloneLocalFKs or the relink path in CloneLocalFKEnforcement.","commonSituations":"Dolt storage errors, interrupted database session, insufficient privileges to read TABLE_CONSTRAINTS, or schema corruption in a cloned workspace.","solutions":["Read the wrapped driver error and fix the underlying DB connectivity/permission issue, then re-run `bd doctor`.","Restart the Dolt-backed storage and confirm `bd doctor` can reach it.","Grant the DB user read access to information_schema.TABLE_CONSTRAINTS.","If the schema is corrupt, restore from git-exported .beads/issues.jsonl and re-import."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var n int\nerr := db.QueryRow(`SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS`).Scan(&n)\nif err != nil {\n\t// cannot read TABLE_CONSTRAINTS; fix privileges/connectivity first\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"if err := ScanSeveredCloneLocalFKs(ctx, db); err != nil && strings.Contains(err.Error(), \"check\") {\n\t// wrapped information_schema failure: back off and retry after fixing DB access\n\treturn err\n}","preventionTips":["Grant SELECT on information_schema to the bd database user","Verify schema names match the fixed CloneLocalFKs spec after migrations","Run doctor scans against a stable, connected Dolt store","Avoid mid-migration scans of the schema"],"tags":["dolt","doctor","foreign-keys","information-schema"],"backgroundTag":"database-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}