Support for SQL triggers
The more complex my projects have become using SQLAlchemy the more I've used SQL triggers. It would be great if SQLAlchemy had builtin support for triggers. This would make it possible to:
- Have re-usable trigger code instead of ugly string based CREATE / DROP DDL statements
- Add later support in alembic for these triggers. My triggers have evolved greatly over time, thus it would be great if alembic noticed these changes automatically when issuing autogenerate.
Comments (5)
-
repo owner -
repo owner that said I didn't yet propose a system for custom "compare" hooks in alembic autogenerate, that would be needed here also, that's what's worth working on on my end.
-
reporter Ok that sounds good. I think custom compare hooks is exactly what I need most here. Thanks again, Mike!
-
repo owner - changed status to wontfix
prefer to improve extensibility of alembic, see https://bitbucket.org/zzzeek/alembic/issue/306/extensible-autogen-compare#comment-None
-
repo owner the new system is checked into master and is documented at http://alembic.readthedocs.org/en/latest/api/autogenerate.html#autogenerating-custom-operation-directives. I have it doing 100% round trip for a hypothetical "create sequence" migration. You should be able to get your trigger thing working fully here, please send me any feedback!
- Log in to comment
im pretty unenthused about adding this, having to support it, and constantly explaining/apologizing for the fact that triggers have entirely different capabilities and behaviors of which I myself have hardly any interest in. The sqlalchemy.ext.compiler extension was created so that I don't have to worry about these things and so that SQLAlchemy Core doesn't need to be plugged up with every possible SQL idiom.
Why not build your own CreateTrigger/ DropTrigger system? Alembic is no problem, as it is now extensible also. Feel free to release a new library on Pypi for creating/altering triggers; the job of SQLA Core and Alembic is only to be extensible enough so that the specifics are maintainable by others on the outside.