-- 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);