-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support PostgreSQL "named schemas" #409
Comments
Michael Bayer (zzzeek) wrote: these are fully supported. see http://alembic.zzzcomputing.com/en/latest/ops.html?highlight=create_table#alembic.operations.Operations.create_table.params.schema for example. is there some specific aspect that you're not seeing? |
Omer Katz () wrote: This script from this StackOverflow question allows you to perform the same schema changes over all named schemas automatically. The limitation of this script is that you have to edit every migration file to change which schema is used. I think what @petri_savolainen is asking is to provide a way to apply the same changes over all schemas automatically using a configuration option. |
Michael Bayer (zzzeek) wrote: You can do that, using translated schema names which is also how you would normally be doing the main application as well for multi-tenant. Go into env.py:
Above will translate the "None" schema name into the given tenant name. If the application shares tenant-based schemas with a default schema that has global tables, then you'd be using some token like "tenant_schema" as the symbol:
and in migration files refer to "tenant_schema" where the actual tenant-specific schema name goes:
|
Omer Katz () wrote: I think this is useful. Can we include this in the documentation? |
Michael Bayer (zzzeek) wrote: sure. people are going to be clamoring for the autogenerate part though so something more complete would be nice. |
Omer Katz () wrote: But in the meanwhile, people who are looking for this feature should at least be able to copy/paste from the documentation. How would you manage multiple schemas for each tenant? There's only so much you can do with automatic generation. |
Michael Bayer (zzzeek) wrote: it would be in the "recipes" section. "autogenerate" would be looking at the application's table metadata compared to a fixed "specimen" schema in order to create new migrations that apply to every tenant's schema. |
Migrated issue, originally created by Petri Savolainen ()
See https://www.postgresql.org/docs/current/static/ddl-schemas.html
For multi-tenant applications, named schemas are commonly used.
The text was updated successfully, but these errors were encountered: