from alembic import op, context
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql import text
# COMMONS
# Base objects for SQL operations are:
# - use op = INSERT, UPDATE, DELETE
# - use connection = SELECT (and also INSERT, UPDATE, DELETE but this object has lot of logics)
metadata = MetaData()
connection = context.get_bind()
tbl = Table('test', metadata, Column('data', Integer), Column("unique_key", String))
# If you want to define a index on the current loaded schema:
# idx1 = Index('test_idx1', tbl.c.data, postgresql_concurrently=True)
def upgrade():
...
queryc = \
"""
CREATE INDEX CONCURRENTLY test_idx1 ON test (data, unique_key);
"""
# it should be possible to create an index here (direct SQL):
connection.execute(text(queryc))
...
Alembic支持
PostgreSQL
并发创建索引我没有使用Postgres,我也不能测试它,但它应该是可能的。 依据:
http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html
Postgres方言版本0.9.9中允许并发索引。 但是,像这样的迁移脚本应该适用于旧版本(直接创建SQL):
在Postgresql中,并发索引是allowed,而Alembic not支持并发操作,一次只能运行一个进程。在
相关问题 更多 >
编程相关推荐