8 SQL migration files covering all 10 tables, RLS policies with SECURITY DEFINER helpers, and seed data for SCW1 site + 3 zones. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWxyMibCuGGtSQSqfajDQ7
27 lines
933 B
SQL
27 lines
933 B
SQL
-- supabase/migrations/20260709000006_notifications_audit.sql
|
|
CREATE TYPE notification_channel AS ENUM ('email', 'whatsapp', 'in_app');
|
|
|
|
CREATE TABLE notifications_log (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
incident_id UUID REFERENCES incidents(id),
|
|
capa_id UUID REFERENCES capa_actions(id),
|
|
channel notification_channel NOT NULL,
|
|
recipient TEXT NOT NULL,
|
|
sent_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
status TEXT NOT NULL DEFAULT 'sent'
|
|
);
|
|
|
|
CREATE TABLE audit_log (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
table_name TEXT NOT NULL,
|
|
record_id UUID NOT NULL,
|
|
action TEXT NOT NULL,
|
|
changed_by UUID REFERENCES users(id),
|
|
changed_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
old_value JSONB,
|
|
new_value JSONB
|
|
);
|
|
|
|
CREATE INDEX audit_log_table_record_idx ON audit_log(table_name, record_id);
|
|
CREATE INDEX audit_log_changed_by_idx ON audit_log(changed_by);
|