25 lines
1.1 KiB
SQL
25 lines
1.1 KiB
SQL
-- Compliance-Audit-Export (Phase 10 Task #67).
|
|
--
|
|
-- Extends AuditEvent with SOC2/HIPAA/GDPR compliance fields and a tamper-evident
|
|
-- hash chain (previousHash, eventHash). Backfills existing rows with safe
|
|
-- defaults; outcome defaults to "success" and dataSensitivity to "internal" so
|
|
-- the integrity-verifier treats pre-migration history as unchained (eventHash
|
|
-- NULL means "not part of chain yet").
|
|
|
|
ALTER TABLE "AuditEvent"
|
|
ADD COLUMN "actorEmail" TEXT,
|
|
ADD COLUMN "actorIp" TEXT,
|
|
ADD COLUMN "actorUserAgent" TEXT,
|
|
ADD COLUMN "sourceModule" TEXT,
|
|
ADD COLUMN "outcome" TEXT NOT NULL DEFAULT 'success',
|
|
ADD COLUMN "dataSensitivity" TEXT NOT NULL DEFAULT 'internal',
|
|
ADD COLUMN "regulatoryScope" TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
|
ADD COLUMN "previousHash" TEXT,
|
|
ADD COLUMN "eventHash" TEXT;
|
|
|
|
CREATE INDEX "audit_event_tenant_action_created_at_idx"
|
|
ON "AuditEvent" ("tenantId", "action", "createdAt");
|
|
|
|
CREATE INDEX "audit_event_tenant_outcome_created_at_idx"
|
|
ON "AuditEvent" ("tenantId", "outcome", "createdAt");
|