简体   繁体   中英

Alembic version table in a separate schemas

I have 100s of alembic version tables for different applications in postgres. Some of the applications use different username for migrations and its possible to set search_path in postgres for those application migrations. Based on the database username, due to search_path, the version tables are created in different postgres schemas. Some of the applications use common username and end up having version table name conflict in public schema as they do not have search_path set to specific schema. How do i enable alembic to use a specific postgres schema to create the version table?

The Alembic EnvironmentContext.configure method takes an argument version_table_schema which allows you to specify the schema to put the version table in. ( Docs )

For example in your 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
        )
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM