sqlalchemy / alembic

A database migrations tool for SQLAlchemy.
MIT License
2.72k stars 238 forks source link

Wrong generation partial index for Boolean condition #1523

Closed mmmcorpsvit closed 1 week ago

mmmcorpsvit commented 2 weeks ago

Expected behavior I will see in alembic script

    op.create_index('ix_unique_vin_active', 'lot', ['vin'], unique=True, postgresql_where=sa.text('active = TRUE'))

but get

    op.create_index("ix_unique_vin_active", "lot", ["vin"], unique=True, postgresql_where=False)

To Reproduce Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved. See also Reporting Bugs on the website.

    __table_args__ = (
        Index('ix_unique_vin_active', 'vin', unique=True, postgresql_where=active == True), 
        # Index("ix_unique_active_vin", "vin", unique=True, postgresql_where=(active == True)), # or like this way
    )

Versions.

CaselIT commented 2 weeks ago

Hi,

What is active in your example? The fact that ot renders true/false suggest it's not a sqlalchemy column element

mmmcorpsvit commented 2 weeks ago

active is a bool field in my model

CaselIT commented 2 weeks ago

can you provide an example of your model?

zzzeek commented 1 week ago

please open a discussion if you have further need for help thanks