【发布时间】:2020-08-06 13:43:31
【问题描述】:
我有一个 Postgres 服务器,其中有一个数据库。这个数据库是我们的数据仓库。我们在此数据库中为每个软件应用程序提供了一个架构。
我正在开发一个新项目,我正在使用 sqlalchemy 的 alembic 创建架构迁移。但是,由于我的数据库的设置方式...看起来修订生成器的 --autogenerate 选项正在扫描数据库中的所有模式。
我找不到将检查限制为仅一种模式的选项。我发现的唯一选择是创建一个函数以传递到 alembic 上下文中的 inclue_object 参数。因此,alembic 将扫描所有模式,但仅在该函数返回 true 时才使用模式/表。这不太理想,因为我有数百个表......所以这个过程很慢。
def include_object(object, name, type_, reflected, compare_to):
print(object, name, type_, reflected, compare_to)
if type_ == 'table' and object.schema != 'leads_manager':
print('returning false')
return False
else:
print('returning true')
return True
def run_migrations_offline():
url = get_db_uri()
context.configure(
url=url,
target_metadata=target_metadata,
include_object=include_object,
)
with context.begin_transaction():
context.execute('SET search_path TO leads_manager')
context.run_migrations()
有人知道如何将 alembic 自动生成限制为 postgres 中的一种模式吗?
【问题讨论】:
-
在功能、特性和设置方面巨大的 sqlalchemy 真是太疯狂了
标签: alembic