From 9f41ed4f8e52ab1696d32edfab2274d073aef894 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Mon, 9 Mar 2026 23:54:20 +0100 Subject: [PATCH] fix: CREATE audit table IF NOT EXISTS before ALTER in migration 042 Co-Authored-By: Claude Opus 4.6 --- .../migrations/042_company_profile_project_id.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend-compliance/migrations/042_company_profile_project_id.sql b/backend-compliance/migrations/042_company_profile_project_id.sql index bdcab38..23f933c 100644 --- a/backend-compliance/migrations/042_company_profile_project_id.sql +++ b/backend-compliance/migrations/042_company_profile_project_id.sql @@ -59,7 +59,18 @@ BEGIN END IF; END $$; --- 7. Add audit log project_id column too +-- 7. Create audit table if not exists, then add project_id +CREATE TABLE IF NOT EXISTS compliance_company_profile_audit ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + tenant_id VARCHAR(255) NOT NULL, + action VARCHAR(20) NOT NULL, + changed_fields JSONB, + changed_by VARCHAR(255), + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE INDEX IF NOT EXISTS idx_company_profile_audit_tenant ON compliance_company_profile_audit(tenant_id); + ALTER TABLE compliance_company_profile_audit ADD COLUMN IF NOT EXISTS project_id UUID;