Answer a question

I have a library that's part of a bigger project. The library uses its own schema in a (PostgreSQL) database shared with the larger project.

I want to use alembic revision --autogenerate to only generate migrations for the library's schema and ignore changes to the tables in the main/default schema. Is there any option for doing this?

FWIW, I've tried the include_schemas=False parameter to context.configure in env.py, but it doesn't seem to do anything.

Answers

It seems I can use include_object in conjunction with include_schemas

In alembic/env.py:

def include_object(object, name, type_, reflected, compare_to):
    if type_ == 'table' and object.schema != MY_SCHEMA:
        return False

    return True

...
context.configure(..., include_object=include_object, ...)
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐