Skip to content

Functional index that is also a UnaryExpression confuses autogeneration #392

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

Closed
sqlalchemy-bot opened this issue Oct 27, 2016 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Dan Craig

Ran across an issue that looks related to #282. I added an index that is a coalesce of other columns, but in descending order, like so:

Index('ix_build_times', func.coalesce(Build.finish_time, Build.start_time, Build.queued_time).desc())

Alembic, via Flask-Migrate, found this and created the index when I autogenerated the migration. It probably also printed the reflection warning, but I don't recall.

op.create_index('ix_build_times', 'build', [sa.text(u'coalesce(finish_time, start_time, queued_time) DESC')], unique=False)

But when I had my next, unrelated migration to autogenerate, it again found that index and added it to the migration, which then fails during the upgrade because the index already exists.

Could this be due to the fact that desc() produces a UnaryExpression, even though it's a functional index, causing it to miss the check at https://bitbucket.org/zzzeek/alembic/commits/46761f9d868c#Lalembic/ddl/postgresql.pyT113 ?

I tried adding that index to alembic:excludes in alembic.ini, but it still created it. If there are any other ways to tell Alembic to ignore that, I'd appreciate knowing. For now I guess I'll just have to manually delete the create/drop index lines from autogenerated migrations going forward.

Versions:

  • postgresql 9.4.1
  • alembic==0.8.8
  • Flask-SQLAlchemy==2.1
  • SQLAlchemy==1.0.15
@sqlalchemy-bot
Copy link
Author

Changes by Dan Craig:

  • edited description

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

yep this seems to be the case.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

Unwrap unaryexpression when testing for functional index

Fixed bug in Postgresql "functional index skip" behavior where a
functional index that ended in ASC/DESC wouldn't be detected as something
we can't compare in autogenerate, leading to duplicate definitions
in autogenerated files.

Change-Id: I0fdfee69a89da575078a687bb4551088fb1b67d7
Fixes: #392

539227f

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot
Copy link
Author

Dan Craig wrote:

Thanks for fixing that so quickly! Will keep an eye out for release 0.8.9.

@sqlalchemy-bot sqlalchemy-bot added the bug Something isn't working label Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant