【发布时间】:2017-03-23 11:39:32
【问题描述】:
我在 Alembic 中有一个依赖于特定后端的修订版,但语义并未明确依赖它(只会让事情变得更快)。
我希望我的代码不依赖于特定的后端(即版本在运行时不会出错)。我应该在def upgrade(): 和def downgrade(): 上写什么条件才能不对其他后端运行修订?
我正在考虑的特定示例:以下修订仅在 postgres 中有效。但是,该应用程序仍将在 sqllite 中运行:
def upgrade():
op.execute('CREATE EXTENSION pg_trgm') # requires being superuser
op.execute('CREATE INDEX ix_document_id ON document USING gin (id gin_trgm_ops)')
def downgrade():
op.execute('DROP INDEX ix_document_id')
op.execute('DROP EXTENSION pg_trgm')
按原样,这个 sqllite 中的错误。
【问题讨论】:
标签: python sqlalchemy alembic