Using Alembic for Single Database with Multiple Schemas
See original GitHub issueDescribe your question I’m trying to use alembic to manage database migrations for a postgres database that contains multiple schemas with each schema being used by a different micro-service.
I realised that I have to use a different table for each micro-service otherwise one micro-service’s migration starts deleting other micro-service tables. So I configured each micro-service alembic_version table to be in it’s own schema to avoid clashes.
The problem that I’m facing is that every migration now recreates all the existing tables of the schema. I tried to debug it and one of the solutions was to set include_schemas=True. But this makes alembic scan all other schemas and try to delete all the tables present in them
I’m not sure if I explained the issue well. I can more details as required
Useful links
- The documentation website
- The Cookbook wiki
- The SQLAlchemy documentation website
- Stack Overflow tag
- Alembic Google group
- Gitter chat
Have a nice day!
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (8 by maintainers)
Top Related StackOverflow Question
OK so you have entirely separate alembic environments each with its own env.py correct?
OK last question do your metadata models have a “schema” in them? that is, they look like:
the include_object we are looking for here looks like this:
within the autogenerate process (I’m assuming that’s what we’re talking about when you say “recreate the tables for every migration script.”), you have complete control over what objects are considered by using that hook.
it’s linked in the comment above, that link is:
https://alembic.sqlalchemy.org/en/latest/cookbook.html#rudimental-schema-level-multi-tenancy-for-postgresql-databases