Skip to content

refactor(db): drop schema-per-module — single shared schema - #186

Merged
antosubash merged 1 commit into
mainfrom
worktree-remove-schema-per-module
Jun 3, 2026
Merged

antosubash merged 1 commit into
mainfrom
worktree-remove-schema-per-module

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

  • Removes the schema-per-module machinery from framework/db: create_module_base() no longer takes a provider= kwarg and always builds a flat MetaData. Postgres and SQLite now share the same physical layout (one schema, module-prefixed __tablename__s).
  • Per-module MetaData is retained so Alembic autogenerate can still attribute tables to a module via branch_labels.
  • Adds psycopg2-binary>=2.9 to simple_module_db deps — Alembic's online migrations are sync-only and env.py rewrites the URL +asyncpg → +psycopg2 at migration time.
  • Catch-up migrations for two pre-existing drifts: 873ca2015033 (users refresh_token table) and 168a2882f443 (keycloak_user_cache, first migration of the keycloak module → branch_labels=("keycloak",)).
  • Docs, skills, scaffold template, and CLAUDE.md updated to describe the single-shared-schema invariant; provider-specific comments removed from 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-qualified MetaData. The runtime fell back to SQLite-like behavior in practice. Removing the dead code path also unblocks alembic check on Postgres.

Verification

  • make ci-python-lint — clean (ruff format + ruff check)
  • make ci-check-file-size — clean
  • make test-py — 1280 passed, 2 skipped, 5 deselected
  • alembic upgrade head — clean on SQLite and on a fresh postgres:16 container
  • alembic check — no autogenerate drift
  • Full head → base → head roundtrip — clean on both backends

Branch rebased on top of 4dd4af6 (release: v0.0.17). One conflict resolved: take main's simple_module_core==0.0.17 pin, keep the new psycopg2-binary block.

framework/db/tests/_audit_models.py (landed on main after the worktree branched) needed the provider= kwarg removed to match the new create_module_base() signature — caught and fixed during the post-rebase test run.

Test plan

  • CI is green (lint + test-py + js + file-size cap + e2e smoke)
  • Reviewer skims the migration chain — keycloak head is 168a2882f443 (keycloak), linear single-head graph
  • Confirm framework/db/simple_module_db/provider.py still exists — it's retained for session.py's engine pool tuning (SQLite gets NullPool); only the create_module_base(provider=) parameter is gone

…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.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

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

View logs

@antosubash
antosubash merged commit 0af316f into main Jun 3, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant