20170123151655_add_trigger_for_meta_updated.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:collectors 作者: opentrials 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号