{"record":{"id":"0bb41194a1ab2ba8","repo":"gastownhall/beads","slug":"checking-constraint-s-on-s-w","errorCode":null,"errorMessage":"checking constraint %s on %s: %w","messagePattern":"checking constraint (.+?) on (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/migration_repairs.go","lineNumber":731,"sourceCode":"\tif err := db.QueryRowContext(ctx, `\n\t\tSELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS\n\t\tWHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND INDEX_NAME = ?\n\t`, table, index).Scan(&count); err != nil {\n\t\treturn false, fmt.Errorf(\"checking index %s on %s: %w\", index, table, err)\n\t}\n\treturn count > 0, nil\n}\n\n// schemaConstraintExists reports whether table carries a named constraint --\n// foreign key or check. Unlike schemaHasPrimaryKey it asks about one specific\n// name, which is what an add-if-absent step needs.\nfunc schemaConstraintExists(ctx context.Context, db DBConn, table, constraint string) (bool, error) {\n\tvar count int\n\tif err := db.QueryRowContext(ctx, `\n\t\tSELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS\n\t\tWHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND CONSTRAINT_NAME = ?\n\t`, table, constraint).Scan(&count); err != nil {\n\t\treturn false, fmt.Errorf(\"checking constraint %s on %s: %w\", constraint, table, err)\n\t}\n\treturn count > 0, nil\n}\n\n// schemaShowCreateTable returns a table's CREATE statement. It is the only\n// place Dolt exposes generated-column shape: INFORMATION_SCHEMA.COLUMNS returns\n// EXTRA and GENERATION_EXPRESSION empty for a generated column, and IS_GENERATED\n// does not exist there at all.\nfunc schemaShowCreateTable(ctx context.Context, db DBConn, table string) (string, error) {\n\tvar name, ddl string\n\t// table is a package constant, never caller input; SHOW CREATE TABLE takes\n\t// no placeholders.\n\tif err := db.QueryRowContext(ctx, \"SHOW CREATE TABLE `\"+table+\"`\").Scan(&name, &ddl); err != nil {\n\t\treturn \"\", fmt.Errorf(\"reading SHOW CREATE TABLE %s: %w\", table, err)\n\t}\n\treturn ddl, nil\n}\n","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/migration_repairs.go#L713-L749","documentation":"Wraps a failure from schemaConstraintExists, which probes INFORMATION_SCHEMA.TABLE_CONSTRAINTS for a named foreign-key or check constraint (used by wispDepMissingAnyFinalConstraint, dropWispDepLegacyShape, ensureWispDepFinalKeysAndConstraints). Unlike schemaHasPrimaryKey it asks about one specific name, which add-if-absent steps need. Thrown only on query failure; a missing constraint is a normal result.","triggerScenarios":"The SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS query errors during constraint reconciliation in the wisp_dependencies repair — server unreachable, context cancelled, or driver failure.","commonSituations":"Connection interruption during the multi-step wisp_dependencies reshape; insufficient privileges to read TABLE_CONSTRAINTS; Dolt restart mid-repair.","solutions":["Inspect the wrapped cause and restore connectivity/server.","Re-run the repair; constraint add-if-absent logic is idempotent.","Verify the DB user can SELECT from INFORMATION_SCHEMA.TABLE_CONSTRAINTS.","Check for ctx deadline issues on very large databases and retry with a longer timeout."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var n int\nerr := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS\n  WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? AND CONSTRAINT_NAME=?`, table, constraint).Scan(&n)","typeGuard":"func isSchemaProbeErr(err error) bool {\n    return strings.Contains(err.Error(), \"checking constraint \")\n}","tryCatchPattern":"if err := ensureWispDepFinalKeysAndConstraints(ctx, db); err != nil {\n    if isRetryableDB(err) { return ensureWispDepFinalKeysAndConstraints(ctx, db) }\n    return err\n}","preventionTips":["Grant the DB user SELECT on INFORMATION_SCHEMA.TABLE_CONSTRAINTS","Retry idempotent constraint reconciliation steps","Avoid context cancellation mid-repair","Keep the Dolt server up during the full repair"],"tags":["database","migration","constraint","schema-introspection"],"backgroundTag":"schema-introspection-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}