I am using flask + sqlalchemy + alembic + postgresql, and am trying to find a simple architecture to solve the following problem.
I have a simple database structure, lets say two tables :
-- Users
-- UserItems
My users are in several different domains. I would like to have several of this database structure. For that I have database schemas in SQL. I created the matching class structure using sqlalchemy decalrative_base, and end up with a MetaData object that isn't tied to a specific schema.
Now I need to be able to run alembic's upgrade operation on each schema that I create (dynamically). I can override the target_metadata that alembic uses, but that will disturb the current running processes.
I thought about cloning the metadata, creating a "Like metadata1, but with schema XYZ" and feeding that to alembic, but I didn't find a way to do this.
Is the correct approach to clone the metadata and modify the schema of all the tables? Is there a simple way to do this?
Is there a different way to apply an alembic operation on multiple schemas in the same database?
Thanks