Conditionally creating tables in PostgresQL with "unlogged" prefix in certain environments #1108
-
I would like to invoke create table migration operations with a prefix of "unlogged" when running in local and continuous integration environments but without that prefix when the migrations are run elsewhere. From what I understand about the SQLalchemy architecture I think this needs to happen in alembic. I've considered/investigated various options:
Out of these I would much prefer 2 being available (perhaps there is a reason this isn't implemented). I've got closest with 4, although my solution doesn't deal with sqlalchemy plugins at the moment and feels like it will be quite brittle. If anyone has done something similar I'd love to hear about it. If you have pointers for which of the above will be the cleanest solution or another solution I've not considered I'd love to hear about it. footnote: I'm a career-long developer but just under a year with Python/SQLalchemy/Alembic |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
OK, there are ways to affect that at the SQLAlchemy level as well, a table prefix is a pretty simple thing so a compiles against
I would stay away from metaclasses in all circumstances. SQLAlchemy itself uses them only for py2 compat, in 2.0 they are mostly replaced with
Alembic is also going to use that same
in this case you are ultimately looking to swap out the
I think a |
Beta Was this translation helpful? Give feedback.
-
I came across this as part of trying out a solution I found on StackOverflow that was provided by Mike Bayer about doing partitioning with Oracle. which can solve my issue. Although I'm struggling on how to get alembic to run the function decorator with @compiles when I do run a "migrate" command to create my migration file. Assuming I understand it is suppose to work that way in the first place. Any advice would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
OK, there are ways to affect that at the SQLAlchemy level as well, a table prefix is a pretty simple thing so a compiles against
CreateTable
could achieve this, if you had the compiler hook looking at a global variable.I would s…