Open AurelienJoy opened 3 weeks ago
Hi,
thanks for reporting. Here the issue seems to be when compiling the statement, not autogenerate
So the create index is managed by sqlalchemy.
@zzzeek what do you think is best here? Modify what is rendered by autogenerate, so render sa.text('(coalesce(team_id, 0))')
, or modify the create index in sqlalchemy to add ()
to text
elements?
I feel like this cant be the only case where some artificial parenthesis need to be added, nothing else in mysql / pg / sql server dialects?
indeed, take a look at https://github.com/sqlalchemy/alembic/blob/b8e2c3589455d46eaef7b34773e50f04a0725fe8/alembic/ddl/postgresql.py#L427-L448. likely the same exact code to add to mysql.py
Good catch. I forgot to look for self_group
Describe the bug
When we declare an index using a coalesce function, the SQL migration instruction produced is invalid because it is missing some parenthesis around the coalesce function.
Example of the invalid generated alembic instruction:
And the invalid SQL instruction produced:
Expected behavior
The valid expected SQL instruction is:
To Reproduce
Auto-generate:
Error
Versions.
Additional context
Also when doing an
alembic check
after the index creation, it prints a warning:Is it expected ? How can I fix it ?
Have a nice day!