我有一对夫妇,我想运行后创建表的自定义DDL语句:
update_function = DDL("""
CREATE OR REPLACE FUNCTION update_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'pgplsql';
""")
update_trigger = DDL("""
CREATE TRIGGER update %(table)s_timestamp BEFORE UPDATE
ON %(table)s FOR EACH ROW EXECUTE PROCEDURE update_timestamp();
""")
我已经把它贴他们是这样的:
event.listen(Session.__table__, 'after_create', update_function)
event.listen(Session.__table__, 'after_create', update_trigger)
当我做create_all
,我得到我期望的SQL:
CREATE OR REPLACE FUNCTION update_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'pgplsql';
CREATE TRIGGER update session_timestamp BEFORE UPDATE
ON session FOR EACH ROW EXECUTE PROCEDURE update_timestamp();
但是,当我使用升级蒸馏器,语句不会出现:
-- Running upgrade c0d470e5c81 -> 6692fad7378
CREATE TABLE session (
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT 'CURRENT_TIMESTAMP',
updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT 'CURRENT_TIMESTAMP',
id VARCHAR(32) NOT NULL,
owner_id INTEGER,
database_id VARCHAR(32),
content TEXT,
PRIMARY KEY (id),
FOREIGN KEY(database_id) REFERENCES database (id),
FOREIGN KEY(owner_id) REFERENCES users (id)
);
INSERT INTO alembic_version (version_num) VALUES ('6692fad7378');
有没有办法让蒸馏器来触发“after_create”事件?