I\'ve got a couple of custom DDL statements that I want to run after create table:
update_function = DDL(\"\"\"
Expanding on @zzzeek's answer, this helper works for me:
from sqlalchemy import Table
from sqlalchemy.event import listen
from functools import partial
def on_table_create(class_, ddl):
def listener(tablename, ddl, table, bind, **kw):
if table.name == tablename:
ddl(table, bind, **kw)
listen(Table,
'after_create',
partial(listener, class_.__table__.name, ddl))
Then you'd do:
on_table_create(Session, update_function)
on_table_create(Session, update_trigger)