SQLAlchemy: Declarative ORM - build index using GIST and TSRANGE

Viewed 1769

I'd like to build an index that essentially looks like this in sql:

CREATE INDEX IF NOT EXISTS new_index ON schema.tablename USING gist (tsrange(start, "end"))

Where my declarative ORM model looks something like this:

import sqlalchemy as sa

class Tablename(Mixins):

    __table_args__ = (
        sa.Index('index_name', postgresql_using="gist"),  # ????
        {'schema': 'schema'}
        )

    start = sa.Column(pg.TIMESTAMP, autoincrement=False, primary_key=True)
    end = sa.Column(pg.TIMESTAMP, nullable=False)

And later, I'd like to use alembic which should include a downgrade such as:

 op.drop_index('index', 'tablename', schema='schema')

Which effectively has the following SQL:

 DROP INDEX IF EXISTS schema.index
1 Answers
Related