def upgrade():
conn = op.get_bind()
func = sa.DDL("""CREATE FUNCTION set_meta_updated()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
NEW.meta_updated := now();
RETURN NEW;
END;
$$;""")
conn.execute(func)
for table in updatable_tables:
trigger_params = {'trigger': ('%s_set_meta_updated' % table), 'table': table}
trigger = ("""CREATE TRIGGER %(trigger)s
BEFORE UPDATE ON %(table)s
FOR EACH ROW EXECUTE PROCEDURE set_meta_updated();""" % trigger_params)
conn.execute(trigger)
20170123151655_add_trigger_for_meta_updated.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录