1

Say I have a Postgres database with two different schema's, one called public and one called 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. 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? Or should I just create another database as a dev database and just backup the prod database to the development database?

davidism
  • 121,510
  • 29
  • 395
  • 339
spitfiredd
  • 2,897
  • 5
  • 32
  • 75
  • Have you read https://stackoverflow.com/questions/9298296/sqlalchemy-support-of-postgres-schemas? It probably isn't the answer, but it has something in common. – Ilja Everilä Mar 21 '18 at 20:34

1 Answers1

3

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:

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

And then update your table_args:

__table_args__ = {'schema': db_schema }
RyanH
  • 991
  • 7
  • 13