refactor(db): drop schema-per-module — single shared schema - #186
Merged
Merged
Conversation
…es + SQLite
All module tables now live in the host's single schema on every backend.
Per-module `MetaData` is retained so Alembic autogenerate can attribute
tables to a module via `branch_labels`, but the schema-per-module
provider/auto-detect machinery is gone.
- framework/db: `create_module_base()` no longer takes `provider=`; always
builds a flat `MetaData`. `psycopg2-binary` added as a sync driver dep
for Alembic.
- Removed `test_postgres_schema_per_module.py` and provider-related test
cases; updated `_models.py` / `test_base.py` / `test_mixins.py`.
- Docs, skills, CLAUDE.md, and the new-module scaffold template updated
to describe a single shared schema (no Postgres/SQLite divergence).
- modules/{background_tasks,file_storage,permissions}: removed
provider-specific comments from `models.py`.
Catch-up migrations for two pre-existing drifts:
- 873ca2015033_users_refresh_token_table — adds `users_refresh_token`.
- 168a2882f443_keycloak_initial_schema — adds `keycloak_user_cache`
with `branch_labels=("keycloak",)`.
Verified: `alembic check` clean, full base↔head roundtrip clean on
Postgres 16 and SQLite, `make doctor` clean, 1273 pytest tests pass.
Deploying simple-module-python with
|
| Latest commit: |
aa3ded3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://44469fa2.simple-module-python.pages.dev |
| Branch Preview URL: | https://worktree-remove-schema-per-m.simple-module-python.pages.dev |
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.
Summary
framework/db:create_module_base()no longer takes aprovider=kwarg and always builds a flatMetaData. Postgres and SQLite now share the same physical layout (one schema, module-prefixed__tablename__s).MetaDatais retained so Alembic autogenerate can still attribute tables to a module viabranch_labels.psycopg2-binary>=2.9tosimple_module_dbdeps — Alembic's online migrations are sync-only andenv.pyrewrites the URL+asyncpg → +psycopg2at migration time.873ca2015033(usersrefresh_tokentable) and168a2882f443(keycloak_user_cache, first migration of the keycloak module →branch_labels=("keycloak",)).modules/{background_tasks,file_storage,permissions}/models.py.Why
The codebase claimed Postgres-schema-per-module but it had never actually worked — module-internal FK strings like
"background_tasks_task_execution.id"are flat-named and would fail to resolve against schema-qualifiedMetaData. The runtime fell back to SQLite-like behavior in practice. Removing the dead code path also unblocksalembic checkon Postgres.Verification
make ci-python-lint— clean (ruff format + ruff check)make ci-check-file-size— cleanmake test-py— 1280 passed, 2 skipped, 5 deselectedalembic upgrade head— clean on SQLite and on a freshpostgres:16containeralembic check— no autogenerate drifthead → base → headroundtrip — clean on both backendsBranch rebased on top of
4dd4af6(release: v0.0.17). One conflict resolved: take main'ssimple_module_core==0.0.17pin, keep the newpsycopg2-binaryblock.framework/db/tests/_audit_models.py(landed on main after the worktree branched) needed theprovider=kwarg removed to match the newcreate_module_base()signature — caught and fixed during the post-rebase test run.Test plan
168a2882f443 (keycloak), linear single-head graphframework/db/simple_module_db/provider.pystill exists — it's retained forsession.py's engine pool tuning (SQLite getsNullPool); only thecreate_module_base(provider=)parameter is gone