Skip to content

Render the expressions of expression indexes - #493

Open
jayhemnani9910 wants to merge 1 commit into
agronholm:masterfrom
jayhemnani9910:fix/render-expression-indexes
Open

jayhemnani9910 wants to merge 1 commit into
agronholm:masterfrom
jayhemnani9910:fix/render-expression-indexes

Conversation

@jayhemnani9910

Copy link
Copy Markdown

Changes

Expression indexes lose their expressions. From a Postgres table with

create unique index users_email_lower on users (lower(email));
create index users_mixed on users (id, lower(email));

sqlacodegen writes Index('users_email_lower', unique=True) and Index('users_mixed', 'id'). metadata.create_all() then fails (CREATE UNIQUE INDEX users_email_lower ON users ()), and the mixed index silently becomes a plain index on id, so a case-insensitive unique rule is lost.

render_index rendered only index.columns. It now renders index.expressions, which SQLAlchemy reflects in order: column names as before, other expressions as text(...); text is imported when an index has one.

Checklist

  • You've added tests (in tests/) which would fail without your patch: test_expression_indexes
  • You've added a new changelog entry (in CHANGES.rst). (PR link to be added once the PR exists)

pytest: 159 passed; the 6 tests/test_cli.py failures here (the sqlacodegen script isn't on PATH in my venv) are the same without this change. Reflected the schema above from Postgres 16: the generated models now create_all on an empty database, and both indexes come back with lower(email).

@jayhemnani9910
jayhemnani9910 force-pushed the fix/render-expression-indexes branch from 1013761 to 0bee308 Compare November 19, 2026 06:02
@coveralls

coveralls commented Nov 19, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 97.859% (+0.006%) from 97.853% — jayhemnani9910:fix/render-expression-indexes into agronholm:master

This branch has not been deployed

No deployments
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.

2 participants