-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alembic always detects changes on indexes that use to_tsvector() #1390
Comments
Hi, Index expression compare was added to postgresql, and this seems to be an unsupported case. |
Hi @CaselIT, thank you very much for your fast response! I've just added the code of one of the generated migrations so you can see how they look like. Yes, I'll ignore these 3 indexes while this case is unsupported. Best regards. |
@CaselIT should we have some doc notes about this specifically for indexes on PostgreSQL? since this is going to go on for a long time |
Well we kinda said "next issue we get we place this under a config flag" so we could do that. I think the regexp we use to remove the type cast used by pg is not detecting it in that complex case, so that should be fixed, but I guess it will not be the last issue we get |
I'm running into this as well, but in my case it seems to related to Alembic not matching PSQL's cast expressions. This migration is created every single time. def upgrade() -> None:
op.drop_index('idx_user_email_search_idx', table_name='user', postgresql_using='gin')
op.create_index('idx_user_email_search_idx', 'user', [sa.text("to_tsvector(CAST('simple' AS REGCONFIG), CAST(coalesce(email, '') AS TEXT))")], unique=False, postgresql_using='gin')
def downgrade() -> None:
op.drop_index('idx_user_email_search_idx', table_name='user', postgresql_using='gin')
op.create_index('idx_user_email_search_idx', 'user', [sa.text("to_tsvector('simple'::regconfig, COALESCE(email, ''::character varying)::text)")], unique=False, postgresql_using='gin')
|
See also #1485 Shame there does not seem to be the equivalent of "NOT VALID" for indexes, otherwise we could have made pg compare the expression directly. |
Since I upgraded to Alembic 1.13.1, SQLAlchemy 2.0.25, Flask-SQLAlchemy 3.1.1, Flask 3.0.0 and Python 3.12, everytime I run
flask db migrate
Alembic detects unexisting changes on indexes that useto_tsvector()
for full text search using PostgreSQL 16. It keeps creating migrations to drop and recreate those unchanged indexes again and again.The Alembic output is:
The affected models look as follows (simplified):
One of the multiple generated migrations looks like follows:
When I was using Alembic 1.7.6, SQLAlchemy 1.4.31, Flask-SQLAlchemy 2.5.1, Flask 2.0.3 and Python 3.10 this didn't happen as there was no support for this kind of indexes at that moment.
I hope this can get resolved soon.
Best regards.
The text was updated successfully, but these errors were encountered: