{"record":{"id":"3379a2b8c2a52c22","repo":"gastownhall/beads","slug":"checking-index-s-on-s-w","errorCode":null,"errorMessage":"checking index %s on %s: %w","messagePattern":"checking index (.+?) on (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/migration_repairs.go","lineNumber":717,"sourceCode":"\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_TYPE = 'PRIMARY KEY'\n\t`, table).Scan(&count); err != nil {\n\t\treturn false, err\n\t}\n\treturn count > 0, nil\n}\n\n// schemaIndexExists reports whether table carries an index (or unique key) of\n// the given name. STATISTICS rather than TABLE_CONSTRAINTS because plain\n// secondary indexes are not constraints and never appear in the latter.\nfunc schemaIndexExists(ctx context.Context, db DBConn, table, index string) (bool, error) {\n\tvar count int\n\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","sourceCodeStart":699,"sourceCodeEnd":735,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/migration_repairs.go#L699-L735","documentation":"Wraps a failure from schemaIndexExists, which probes INFORMATION_SCHEMA.STATISTICS to see whether a named index exists on a table (used by ensureWispIsBlockedIndex, dropWispDepLegacyShape, ensureWispDepFinalKeysAndConstraints). STATISTICS is used because plain secondary indexes are not constraints. Thrown only when the probe query itself fails, not when the index is missing.","triggerScenarios":"The SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS query errors during a repair step — Dolt server down, context cancelled, driver failure, or restricted permissions on INFORMATION_SCHEMA.","commonSituations":"Connection drop mid-repair; read-only account; Dolt server restart between repair steps; long migration exceeding ctx timeout.","solutions":["Inspect the wrapped driver error and restore DB connectivity.","Re-run the repair — index checks and their follow-up actions are idempotent add-if-absent operations.","Confirm the DB user can query INFORMATION_SCHEMA.STATISTICS.","Increase the context timeout if repairs are timing out on large databases."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var n int\nerr := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS\n  WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? AND INDEX_NAME=?`, table, index).Scan(&n)","typeGuard":"func isTransientDBErr(err error) bool {\n    var ne net.Error\n    return errors.As(err, &ne) || errors.Is(err, context.DeadlineExceeded)\n}","tryCatchPattern":"if err := ensureWispIsBlockedIndex(ctx, db); err != nil {\n    if isTransientDBErr(err) { return ensureWispIsBlockedIndex(ctx, db) } // idempotent\n    return err\n}","preventionTips":["Confirm SELECT access to INFORMATION_SCHEMA.STATISTICS","Retry repairs on transient errors — checks are add-if-absent","Keep context deadlines generous","Run against a connected, healthy server"],"tags":["database","migration","index","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"}