{"record":{"id":"ba6e6d00c2459e94","repo":"gastownhall/beads","slug":"table-not-found-schema-migrations-at-q","errorCode":null,"errorMessage":"table not found: schema_migrations at %q","messagePattern":"table not found: schema_migrations at %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/storage/schema/migration_content_hashes.go","lineNumber":63,"sourceCode":"\t)\n\tif ref == \"\" {\n\t\trows, err = db.QueryContext(ctx, \"SELECT version, content_hash FROM schema_migrations\")\n\t} else {\n\t\tif verr := validateMigrationRef(ref); verr != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid ref: %w\", verr)\n\t\t}\n\t\t// A cached ref may legitimately predate schema_migrations or its\n\t\t// content_hash column. Probe the historical shape before selecting from\n\t\t// it: letting the SELECT fail emits a Dolt server warning for every\n\t\t// read-only doctor run.\n\t\t//nolint:gosec // G201: ref is validated above — AS OF requires a literal, not a bind param\n\t\thasTable, queryErr := queryHasRows(ctx, db,\n\t\t\tfmt.Sprintf(\"SHOW TABLES AS OF '%s' LIKE 'schema_migrations'\", ref))\n\t\tif queryErr != nil {\n\t\t\treturn nil, queryErr\n\t\t}\n\t\tif !hasTable {\n\t\t\treturn nil, fmt.Errorf(\"table not found: schema_migrations at %q\", ref)\n\t\t}\n\t\t//nolint:gosec // G201: ref is validated above — AS OF requires a literal, not a bind param\n\t\thasContentHash, queryErr := queryHasRows(ctx, db,\n\t\t\tfmt.Sprintf(\"SHOW COLUMNS FROM schema_migrations AS OF '%s' LIKE 'content_hash'\", ref))\n\t\tif queryErr != nil {\n\t\t\treturn nil, queryErr\n\t\t}\n\t\tif !hasContentHash {\n\t\t\treturn nil, fmt.Errorf(\"unknown column content_hash in schema_migrations at %q\", ref)\n\t\t}\n\t\t//nolint:gosec // G201: ref is validated above — AS OF requires a literal, not a bind param\n\t\trows, err = db.QueryContext(ctx,\n\t\t\tfmt.Sprintf(\"SELECT version, content_hash FROM schema_migrations AS OF '%s'\", ref))\n\t}\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer rows.Close()","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/migration_content_hashes.go#L45-L81","documentation":"When reading at a historical ref, the code first probes \"SHOW TABLES AS OF '<ref>' LIKE 'schema_migrations'\"; if the table did not exist at that commit, this error is returned. It is informational about history: the cached ref predates the introduction of schema_migrations, so no migration hashes can be read at that point.","triggerScenarios":"Calling ReadMigrationContentHashes with a ref pointing to a commit before schema_migrations was created — e.g. an old remote head, a freshly cloned repo whose ref predates the migrations framework, or comparing against a wrong/very old ref.","commonSituations":"Remote branch not yet pulled/migrated; comparing current DB against an ancient commit; newly initialized database where migrations haven't run at the ref; typos resolving to an old tag.","solutions":["Point the ref at a commit where schema_migrations exists (e.g. current remote main after migrations ran).","Run migrations on the remote/repo so schema_migrations exists at the ref.","If the ref legitimately predates migrations, treat as \"no migrations\" in the caller instead of failing (check errors.Is/contains).","Sync/pull the remote so the ref resolves to a recent commit."],"exampleFix":"// before: hard failure on ancient ref\nhashes, err := schema.ReadMigrationContentHashes(ctx, db, ref)\nif err != nil { return err }\n// after: tolerate pre-migrations history\nhashes, err := schema.ReadMigrationContentHashes(ctx, db, ref)\nif err != nil && strings.Contains(err.Error(), \"table not found: schema_migrations\") {\n    hashes = map[string]string{} // no migrations at ref\n    return hashes, nil\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"hashes, err := schema.ReadMigrationContentHashes(ctx, db, ref)\nif err != nil && strings.Contains(err.Error(), \"table not found: schema_migrations\") {\n    hashes = map[string]string{} // ref predates migrations table\n}","preventionTips":["Only compare against refs at or after the migrations framework was introduced.","Keep the remote synced so the ref resolves to recent commits.","Handle the pre-migrations case as \"no migrations\" rather than an error."],"tags":["database","dolt","migration","time-travel"],"backgroundTag":"schema-migrations-missing-at-ref","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}