{"record":{"id":"bca2ed949fe911fc","repo":"gastownhall/beads","slug":"reading-show-create-table-s-w","errorCode":null,"errorMessage":"reading SHOW CREATE TABLE %s: %w","messagePattern":"reading SHOW CREATE TABLE (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/migration_repairs.go","lineNumber":745,"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_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\n// schemaColumnInPrimaryKey reports whether column is (one of) table's PRIMARY\n// KEY column(s) specifically -- distinct from schemaHasPrimaryKey, which only\n// says a primary key exists without saying which column(s) it covers.\nfunc schemaColumnInPrimaryKey(ctx context.Context, db DBConn, table, column string) (bool, error) {\n\tvar count int\n\tif err := db.QueryRowContext(ctx, `\n\t\tSELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE\n\t\tWHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ? AND CONSTRAINT_NAME = 'PRIMARY'\n\t`, table, column).Scan(&count); err != nil {\n\t\treturn false, err\n\t}\n\treturn count > 0, nil\n}\n","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/migration_repairs.go#L727-L763","documentation":"Wraps a failure to run and read SHOW CREATE TABLE for a table. This is the only way Dolt exposes generated-column shape — INFORMATION_SCHEMA.COLUMNS returns EXTRA and GENERATION_EXPRESSION empty for generated columns — so wispDepHasStoredGeneratedDependsOnID depends on it. Thrown when the query fails or the row cannot be scanned (e.g., the table does not exist at call time).","triggerScenarios":"SHOW CREATE TABLE `<table>` errors: the table was dropped between the existence check and this call, the server is down, or the Scan into (name, ddl) fails because no row was returned.","commonSituations":"Race where a concurrent migration drops/renames the table mid-repair; querying a database where the table never existed because the caller skipped the presence check; connection failure.","solutions":["Confirm the table still exists before calling (or re-run the repair, which re-checks presence).","Inspect the wrapped driver error; restore connectivity if the server is down.","If the table genuinely does not exist and the repair expected it, determine whether a prior migration step already replaced it — re-running the repair flow should take the correct branch.","Check Dolt server version supports SHOW CREATE TABLE output with generated-column expression."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure the table exists before asking for its DDL\nexists, err := schemaTableExists(ctx, db, table)\nif err != nil || !exists { /* skip SHOW CREATE TABLE path */ }","typeGuard":"func isMissingTableErr(err error) bool {\n    return strings.Contains(err.Error(), \"doesn't exist\") || strings.Contains(err.Error(), \"not found\")\n}","tryCatchPattern":"ddl, err := schemaShowCreateTable(ctx, db, table)\nif err != nil {\n    if isMissingTableErr(err) { return nil /* table already replaced/dropped */ }\n    return err\n}","preventionTips":["Always check table existence before SHOW CREATE TABLE","Avoid concurrent migrations that drop/rename the same table","Run within a single migration session so the table cannot disappear mid-check","Use a Dolt version that reports generated-column shape in SHOW CREATE TABLE"],"tags":["database","migration","ddl","generated-columns"],"backgroundTag":"show-create-table-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}