Skip to content
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

Gin index on JSONB specific key not detected with autogenerate #469

Closed
sqlalchemy-bot opened this issue Nov 29, 2017 · 4 comments
Closed
Labels
autogenerate - detection bug Something isn't working

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Pierre Kephas (@kephas)

Hello,

I have a table with a JSONB column :

meta = sa.Column('metadata', sa.ext.mutable.MutableDict.as_mutable(sa.dialects.postgresql.JSONB),
                     nullable=True, server_default='{}')

And I want a GIN index on the some_key key (see https://www.postgresql.org/docs/current/static/datatype-json.html#JSON-INDEXING if you do not know a lot about GIN indexes).

I declared :

__table_args__ = (
    sa.Index(
        'ix_table_metadata_some_key',
        sa.text('''(metadata->'some_key')'''),
        postgresql_using='gin',
    )
)

Then, running alembic revision -m "Some message" --autogenerate generates an empty migration.

Note: creating a GIN index on meta column works fine.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

you will note the warning:

alembic/util/messaging.py:69: UserWarning: autogenerate skipping functional index ix_table_metadata_some_key; not supported by SQLAlchemy reflection

that is, autogenerate has no way to know if this index already exists in the database. This behavior was added to #282.

You'll need to add this index to your migration script manually.

@sqlalchemy-bot
Copy link
Author

Pierre Kephas (@kephas) wrote:

Hi,

Thanks for your answer.

Yes, I noted the warning, but I forgot to mention it (sorry).

Well, I guess that detecting functional indexes is not easy... But anyway, I already added to my migration script manually. :)

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

sorry!

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autogenerate - detection bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant