8086b8be03
prod-canonical_controls (aus dem DB-Swap) hat weder PK noch Unique auf id → FK InvalidForeignKey. control_uuid bleibt UUID (logische Referenz), wie die bereits FK-lose atom_classification auf prod. [migration-approved] Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
38 lines
1.6 KiB
SQL
38 lines
1.6 KiB
SQL
-- Migration 156: control_suppressions — per-tenant Applicability-Override.
|
|
-- Ein Mandant markiert ein Control als "unbrauchbar / nicht anwendbar" -> es
|
|
-- wird in seinen Use-Case-Ansichten (und künftig Repo-Scans) ausgeblendet.
|
|
-- REVERSIBEL (active=false + reverted_*, Zeile bleibt) und AUDIT-tauglich
|
|
-- (actor + reason + created_at beantworten "warum nicht geprüft?"). PER-TENANT.
|
|
-- Composite PK (tenant_id, control_uuid) = genau eine aktuelle Zeile je
|
|
-- Mandant+Control; Re-Suppress reaktiviert. Additiv, idempotent. [migration-approved]
|
|
-- HINWEIS: KEINE FK auf canonical_controls(id) — die prod-DB (aus dem DB-Swap)
|
|
-- hat dort weder PK noch Unique auf id (atom_classification ist dort ebenfalls
|
|
-- FK-los). control_uuid referenziert Controls daher nur logisch.
|
|
|
|
SET search_path TO compliance, public;
|
|
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables
|
|
WHERE table_schema = 'compliance'
|
|
AND table_name = 'canonical_controls') THEN
|
|
|
|
CREATE TABLE IF NOT EXISTS control_suppressions (
|
|
tenant_id UUID NOT NULL,
|
|
control_uuid UUID NOT NULL,
|
|
reason TEXT,
|
|
actor VARCHAR(120),
|
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
reverted_at TIMESTAMPTZ,
|
|
reverted_by VARCHAR(120),
|
|
revert_reason TEXT,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
PRIMARY KEY (tenant_id, control_uuid)
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_ctrl_suppr_tenant_active
|
|
ON control_suppressions(tenant_id, active);
|
|
|
|
END IF;
|
|
END $$;
|