mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Add trigger that ensures row in template_redacted is created
when adding new template through a migration
This commit is contained in:
@@ -21,6 +21,32 @@ def upgrade():
|
|||||||
;
|
;
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
create or replace function insert_redacted()
|
||||||
|
returns trigger AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id)
|
||||||
|
SELECT templates.id, FALSE, now(), templates.created_by_id
|
||||||
|
FROM templates
|
||||||
|
WHERE templates.id NOT IN (SELECT template_id FROM template_redacted WHERE template_id = templates.id);
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TRIGGER insert_template_redacted AFTER INSERT ON templates
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE PROCEDURE insert_redacted();
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
pass
|
op.execute("""
|
||||||
|
drop trigger insert_template_redacted ON templates
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
drop function insert_redacted();
|
||||||
|
""")
|
||||||
|
|||||||
Reference in New Issue
Block a user