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
35 lines
1.4 KiB
SQL
35 lines
1.4 KiB
SQL
-- supabase/migrations/20260709000004_evidence_investigations.sql
|
|
CREATE TYPE evidence_stage AS ENUM (
|
|
'report', 'response', 'investigation', 'capa', 'verification'
|
|
);
|
|
|
|
CREATE TABLE evidence_files (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
incident_id UUID NOT NULL REFERENCES incidents(id) ON DELETE RESTRICT,
|
|
stage evidence_stage NOT NULL,
|
|
file_url TEXT NOT NULL,
|
|
file_type TEXT NOT NULL,
|
|
file_hash TEXT NOT NULL, -- immutable after upload (DOSH audit integrity)
|
|
uploaded_by UUID NOT NULL REFERENCES users(id),
|
|
uploaded_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
deleted BOOLEAN NOT NULL DEFAULT false -- NEVER hard-delete; use this flag
|
|
);
|
|
|
|
CREATE TYPE rca_method AS ENUM ('five_why', 'fishbone', 'other');
|
|
|
|
CREATE TABLE investigations (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
incident_id UUID NOT NULL REFERENCES incidents(id) ON DELETE RESTRICT,
|
|
investigator_id UUID NOT NULL REFERENCES users(id),
|
|
method rca_method NOT NULL DEFAULT 'five_why',
|
|
findings_text TEXT,
|
|
root_cause_summary TEXT,
|
|
alcohol_test_result TEXT,
|
|
witness_statement_refs TEXT[],
|
|
completed_at TIMESTAMPTZ,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX evidence_files_incident_idx ON evidence_files(incident_id);
|
|
CREATE INDEX investigations_incident_idx ON investigations(incident_id);
|