fix(db): preserve expression-based indexes in autogenerate - #144
Merged
antosubash merged 1 commit intoMay 13, 2026
Conversation
Closes #140. SQLAlchemy 2.0 can't reflect functional indexes (e.g. `CREATE INDEX ... ON t (lower(email))`) under the SQLite dialect, so Alembic autogenerate silently skips them — leaving SQLite dev DBs without an index that production Postgres has. - Add `make_process_revision_directives(metadata)` in `simple_module_db.migrations`: walks each generated `MigrationScript` and, for any `CreateTableOp` whose table has expression-based indexes in the target metadata, appends a matching `CreateIndexOp` (and the reverse `DropIndexOp` in the downgrade). Dedups against already-emitted ops so the hook is a no-op on Postgres. - Wire the hook into `host/migrations/env.py` and the scaffold template so every existing and `smpy new`-generated host gets it. - Add catch-up migration `41cf2c53660e` that back-fills `ix_users_user_email_lower` on databases already past `3bf3f9db7f7f`. Uses `if_not_exists` / `if_exists` so it's a no-op on installs that somehow already have the index.
Deploying simple-module-python with
|
| Latest commit: |
87f455a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2f58bc5f.simple-module-python.pages.dev |
| Branch Preview URL: | https://feature-feat-autogenerate-si.simple-module-python.pages.dev |
This was referenced May 13, 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.
Summary
process_revision_directiveshook that re-injects expression-based indexes intoCreateTableOpdirectives (with dedup so it's a no-op on Postgres where autogen emits them correctly).host/migrations/env.pyand thesmpy newscaffold template, so every host — existing or freshly scaffolded — gets the fix.41cf2c53660ethat back-fillsix_users_user_email_loweron already-migrated DBs, idempotent viaif_not_exists/if_exists.Closes #140.
Test plan
uv run pytest framework/db/tests/test_migrations.py— 4 new tests inTestProcessRevisionDirectivescover injection, no-op on non-create-table revisions, no double-emit on Postgres, and no-op for plain column indexes.make lint(ruff + ty) — green on all touched files; 300-line file-cap check passes.host/app.db, ranalembic upgrade headon SQLite, confirmedix_users_user_email_loweris present insqlite_master.alembic revision --autogenerateagainst head produces an empty migration (no spurious diff from the hook).