Parameterise PostgreSQL schema throughout the backend#590
Merged
will-langdale merged 7 commits intoJun 9, 2026
Conversation
MB__SERVER__POSTGRES__DB_SCHEMA was only respected by the SQLAlchemy ORM metadata. All Alembic migrations, several raw SQL strings, and the ingest utilities were hardcoded to "mb". - env.py: pass db_schema into Alembic config so migrations can read it - All 25 migration files: replace schema="mb" kwargs, inline FK strings (e.g. ["mb.table.col"]), and raw SQL table references with the parameterised value via op.get_context().config.get_main_option() - First migration: remove CREATE/DROP SCHEMA — the operator is now responsible for creating the schema before running migrations - db.py: parameterise the pre-alembic recovery DROP SCHEMA - orm.py: fix hardcoded schema on the upload_stages Enum type - insert.py, adapter/eval.py: fix schema_name="mb" on temp table calls - justfile: use $MB__SERVER__POSTGRES__DB_SCHEMA in the drop recipe https://claude.ai/code/session_01NBvRFT32ceNrae2sUCjpzb
This comment has been minimized.
This comment has been minimized.
Since migration 1 no longer creates the PostgreSQL schema, it must be provisioned externally before migrations run. - db.py: run_migrations() now creates the schema when bootstrapping a fresh database (pre-alembic path — the path test fixtures always hit) - docker-compose.yml: mount a postgres initdb.d script and forward MB__SERVER__POSTGRES__DB_SCHEMA into the postgres container - docker/postgres-init/01-create-schema.sh: new init script that runs CREATE SCHEMA IF NOT EXISTS on first container startup - docs/server/install.md: document the schema creation prerequisite for production deployments https://claude.ai/code/session_01NBvRFT32ceNrae2sUCjpzb
48f26ae to
1b71ec5
Compare
leo-mazzone
reviewed
Jun 9, 2026
- script.py.mako: inject schema variable at the top of upgrade() and downgrade() so new migrations always have it available - alembic.ini: add fix_schema post-write hook (runs before ruff) that reads MB__SERVER__POSTGRES__DB_SCHEMA from the environment and replaces hardcoded schema strings with the schema variable - fix_schema_hook.py: the hook script (~8 lines) https://claude.ai/code/session_01NBvRFT32ceNrae2sUCjpzb
Signed-off-by: DBT pre-commit check
Signed-off-by: DBT pre-commit check
leo-mazzone
approved these changes
Jun 9, 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.
MB__SERVER__POSTGRES__DB_SCHEMAwas only respected by the SQLAlchemy ORM metadata. All Alembic migrations, several raw SQL strings, and the ingest utilities were hardcoded to "mb".🛠️ Changes proposed in this pull request
env.py: passdb_schemainto Alembic config so migrations can read itschema="mb"kwargs, inline FK strings (e.g.["mb.table.col"]), and raw SQL table references with the parameterised value viaop.get_context().config.get_main_option()CREATE/DROP SCHEMA— the operator is now responsible for creating the schema before running migrationsdb.py: parameterise the pre-alembic recovery DROP SCHEMAorm.py: fix hardcoded schema on the upload_stages Enum typeinsert.py, adapter/eval.py: fixschema_name="mb"on temp table callsjustfile: use$MB__SERVER__POSTGRES__DB_SCHEMAin the drop recipe👀 Guidance to review
Alembic post migration generation hook in action:
🤖 AI declaration
AI written, human reviewed.
✅ Checklist: