Creating schemas in env.py file - are there better approaches to doing this? #1534
Unanswered
bmuriithi1
asked this question in
Usage Questions
Replies: 1 comment
-
Hi, Can't you manually add a new migration that creates the schemas and manually set it to be the first one? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a project which uses alembic for managing postgres database migrations on several schemas in a database, using SQLModel ORM models. The project already has a few migrations. But none of the previous migrations have commands to create schemas, which is a problem when trying to restore a database (eg. after building a new postgres docker container without any data in it).
Our current workaround is to create schemas manually using SQL commands and then apply the database migrations once the schemas are in place.
However I'm thinking that we could add code to our env.py file that loops through our SQLModel models, extracts schemas associated with the model, create schemas if they don't already exist in the database and then run the migration scripts as usual to create tables and perform other actions specified in the migration files.
But before doing this, I was wondering if anyone can think of a better solution?
Beta Was this translation helpful? Give feedback.
All reactions