Autogenerate with a gin index on jsonb field with postgresql #1485
Unanswered
JabberWocky-22
asked this question in
Usage Questions
Replies: 2 comments 5 replies
-
code to repoduce import sqlalchemy as sa
from alembic.autogenerate.api import produce_migrations
from alembic.autogenerate.api import render_python_code
from alembic.migration import MigrationContext
from sqlalchemy.dialects.postgresql import JSONB
metadata = sa.MetaData()
table = sa.Table(
"account",
metadata,
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("extra", JSONB()),
)
table.append_constraint(
sa.Index(
"ix_account_nickname",
table.c.extra["user_info"]["nickname"].astext.label("nickname"),
postgresql_using="gin",
postgresql_ops={"nickname": "gin_trgm_ops"},
)
)
engine = sa.create_engine("postgresql://user:pass@host:1234/db")
conn = engine.connect()
with conn.begin():
metadata.drop_all(conn)
# metadata.create_all(conn)
mc = MigrationContext.configure(connection=conn)
migration_script = produce_migrations(mc, metadata)
upgrade_code = render_python_code(migration_script.upgrade_ops, migration_context=mc)
print(upgrade_code)
downgrade_code = render_python_code(
migration_script.downgrade_ops, migration_context=mc
)
print(downgrade_code) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, thanks for reporting. what should be the correct rendering of the index in the migration? Regarding the index wrong detection this was already reported here #1390 |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a table as shown in the following code
If I try to create a revision with autogenreate, the upgrade ops would like follows:
The create index statement is not correct since the text expresion doesn't have a label, so the oeprator class will take no effect.(Actually not matters much since I only need to adjust once)
Besides, if I try to create a revision after this migration, the index will always be dropped and created.
I can use
include_name
to filter this index, but it seems a bug with index expression comparing.Beta Was this translation helpful? Give feedback.
All reactions