chore(db): replace init_db.sql with authoritative generated schema.sql#59
Open
MoltyCel wants to merge 1 commit into
Open
chore(db): replace init_db.sql with authoritative generated schema.sql#59MoltyCel wants to merge 1 commit into
MoltyCel wants to merge 1 commit into
Conversation
init_db.sql had drifted to 11 tables while the live DB has 53 — and even the 11 shared tables diverged structurally: api_keys carried a phantom `id` column and was missing email/rate_limit/tier/label/notes; agents used `public_key` vs live `public_key_hex`; credentials used a UUID id vs live serial. A fresh instance built from init_db.sql would have crashed on startup. fork-ci.yml papered over this with per-run ALTER TABLE / CREATE TABLE workarounds (api_keys.email, request_log) instead of fixing the source. This replaces init_db.sql with schema.sql — a `pg_dump --schema-only` of the live DB: 53 tables, 2 views, 91 indexes, 17 FK constraints, the credit_transactions append-only trigger. The dated legacy table caep_events_legacy_20260415 is excluded; verified self-contained (no FK or view depends on it, all 5 FK targets defined). schema.sql is a generated artifact and carries a regeneration header — do not hand-edit. CI now loads schema.sql directly with `-v ON_ERROR_STOP=1`, so the build fails loudly if the schema-of-record ever breaks again. The ALTER/CREATE alignment workarounds are removed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
init_db.sqlhad silently become a non-functional schema-of-record. Itdefined 11 tables; the live
moltstackDB has 53 (+2 views, 91indexes, 17 FK constraints). Worse, the 11 shared tables had diverged
structurally — e.g.
api_keyscarried a phantomidcolumn and wasmissing
email/rate_limit/tier/label/notes;agentsusedpublic_keyvs the livepublic_key_hex;credentialsused a UUID idvs the live serial.
A fresh instance built from
init_db.sqlwould have crashed on startup.fork-ci.ymlmasked this with per-runALTER TABLE/CREATE TABLEworkarounds (
api_keys.email,request_log) instead of fixing the source.Surfaced during post-merge review of #58.
Change
schema.sqlpg_dump --schema-onlyof the live DB; authoritative, generated, self-documenting regeneration headerinit_db.sql.github/workflows/fork-ci.ymlschema.sqlwith-v ON_ERROR_STOP=1; ALTER/CREATE workarounds dropped.gitignore!init_db.sql→!schema.sqlVerification
dated legacy table
caep_events_legacy_20260415has no inbound FK orview dependency (checked via
pg_constraint/pg_depend); 0legacyreferences remain in the dump.
pytest-runCI job is now the live replay test — it loadsschema.sqlinto a freshpostgres:16container withON_ERROR_STOP=1,so a broken schema-of-record fails the build loudly.
Not touched (intentionally)
migrations/2026-05-14_credit_schema_alignment.sqlanddocs/specs/2026-05-14_credit-middleware-schema-alignment.mdmentioninit_db.sqlin historical context — left as-is (applied migration /dated spec).
Follow-up
schema.sqlis generated. Long term it should be regenerated from thelive DB on a cadence, or schema changes should flow through
migrations/and be reflected here — otherwise drift returns.
🤖 Generated with Claude Code