From 3a5860ab745de198bf4c8a5e5e6be7c0ac1e08b8 Mon Sep 17 00:00:00 2001 From: Norris Ng <103449568+norrisng-bc@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:21:13 -0700 Subject: [PATCH] Add audit trigger for when invite is consumed Invites are deleted once used, so log this in the audit table --- .../20240703000000_015-invite-audit-trigger.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/src/db/migrations/20240703000000_015-invite-audit-trigger.js diff --git a/app/src/db/migrations/20240703000000_015-invite-audit-trigger.js b/app/src/db/migrations/20240703000000_015-invite-audit-trigger.js new file mode 100644 index 00000000..ce678a73 --- /dev/null +++ b/app/src/db/migrations/20240703000000_015-invite-audit-trigger.js @@ -0,0 +1,15 @@ +exports.up = function (knex) { + return Promise.resolve() + // Create invite audit trigger + .then(() => knex.schema.raw(` + CREATE TRIGGER audit_invite_trigger + AFTER UPDATE OR DELETE ON invite + FOR EACH ROW EXECUTE PROCEDURE audit.if_modified_func(); + `)); +}; + +exports.down = function (knex) { + return Promise.resolve() + // Drop invite audit trigger + .then(() => knex.schema.raw('DROP TRIGGER IF EXISTS audit_invite_trigger ON invite')); +};