Python 3.x 单独模式中的Alembic版本表

Python 3.x 单独模式中的Alembic版本表,python-3.x,alembic,Python 3.x,Alembic,我有100个alembic版本表,用于postgres中的不同应用程序。一些应用程序使用不同的用户名进行迁移,并且可以在postgres中为这些应用程序迁移设置search\u path。基于数据库用户名,由于搜索路径,版本表在不同的postgres模式中创建。一些应用程序使用公共用户名,并最终在公共架构中出现版本表名称冲突,因为它们没有将搜索路径设置为特定架构。如何使alembic能够使用特定的postgres架构来创建版本表?alembic环境上下文。configure方法使用一个参数ver

我有100个alembic版本表,用于postgres中的不同应用程序。一些应用程序使用不同的用户名进行迁移,并且可以在postgres中为这些应用程序迁移设置
search\u path
。基于数据库用户名,由于搜索路径,版本表在不同的postgres模式中创建。一些应用程序使用公共用户名,并最终在公共架构中出现版本表名称冲突,因为它们没有将搜索路径设置为特定架构。如何使alembic能够使用特定的postgres架构来创建版本表?

alembic
环境上下文。configure
方法使用一个参数
version\u table\u schema
,该参数允许您指定要将版本表放入的架构。()

例如,在您的
env.py

from alembic import context
...

def run_migrations_online():
    connectable = config.attributes.get('connection', None)
    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            version_table='alembic_version',
            version_table_schema="my_schema",  # <-- Set the schema name here
        )
    ...
来自alembic导入上下文的

...
def运行迁移在线()
connectable=config.attributes.get('connection',None)
使用connectable.connect()作为连接:
context.configure(
连接=连接,
target\u metadata=target\u metadata,
版本\u table='alembic\u version',
version\u table\u schema=“my\u schema”#