From 3e3cd2bf109acd3746b45c7d5bcee00f3630bb9d Mon Sep 17 00:00:00 2001 From: Samuel Shuert Date: Thu, 25 Jun 2026 23:09:11 +0000 Subject: [PATCH] feat(backend): Add audit log table --- backend/migrations/20260625225718_audit_log.down.sql | 2 ++ backend/migrations/20260625225718_audit_log.up.sql | 12 ++++++++++++ 2 file(s) changed, 14 insertion(s)(+), 0 deletion(s)(-) diff --git a/backend/migrations/20260625225718_audit_log.down.sql b/backend/migrations/20260625225718_audit_log.down.sql new file mode 100644 --- /dev/null +++ b/backend/migrations/20260625225718_audit_log.down.sql @@ -0,0 +1,2 @@ +-- Add down migration script here +DROP TABLE audit_logs; diff --git a/backend/migrations/20260625225718_audit_log.up.sql b/backend/migrations/20260625225718_audit_log.up.sql new file mode 100644 --- /dev/null +++ b/backend/migrations/20260625225718_audit_log.up.sql @@ -0,0 +1,12 @@ +-- Add up migration script here +CREATE TABLE audit_logs ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES users(id), + table_name TEXT NOT NULL, + modified_record_id UUID NOT NULL, + action TEXT NOT NULL, + note TEXT, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + CHECK (action IN ('create', 'update', 'delete')), -- Action should be part of CRUD but READ shouldn't require an audit log + CHECK (action <> 'delete' OR note IS NOT NULL) -- If action is delete require a note +); -- tangled.sh