from sqlalchemy import Table, MetaData, Index meta = MetaData() def _get_indices(meta): meta.reflect() Users = Table("users", meta, autoload=True, autoload_with=meta.bind) Repositories = Table("users", meta, autoload=True, autoload_with=meta.bind) return [ Index("repositories_name_unique_id", Users.c.id, Repositories.c.name, unique=True) ] def upgrade(migrate_engine): meta.bind = migrate_engine for idx in _get_indices(meta): idx.create() def downgrade(migrate_engine): meta.bind = migrate_engine for idx in _get_indices(meta): idx.drop()