简体   繁体   English

Flask-Sqlalchemy Acess不同的架构?

[英]Flask-Sqlalchemy Acess different schema?

Say I have a Postgres database with two different schema's, one called public and one called development . 假设我有一个Postgres数据库,它有两个不同的模式,一个叫做public ,一个叫做development I know at the class level I can set __table_args__ = {"schema":"schema_name"} for each model, but if I wanted to switch from development to prod. 我知道在类级别我可以为每个模型设置__table_args__ = {"schema":"schema_name"} ,但是如果我想从开发切换到prod。 wouldn't I haven't to update all my models? 我不会更新我的所有型号吗?

Is there a way to set the schema for the dev and prod schemas in flask? 有没有办法为烧瓶中的dev和prod架构设置架构? Or should I just create another database as a dev database and just backup the prod database to the development database? 或者我应该只创建另一个数据库作为开发人员数据库,并将prod数据库备份到开发数据库?

Assuming there's something in the config along the lines of PRODUCTION = False/True, then you should be able to set the schema by adding into the models: 假设配置中的某些内容沿着PRODUCTION = False / True,那么您应该能够通过添加到模型中来设置模式:

if app.config['PRODUCTION']:
    db_schema = 'public'
else:
    db_schema = 'development'

And then update your table_args: 然后更新你的table_args:

__table_args__ = {'schema': db_schema }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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