Files
breakpilot-compliance/backend-compliance/migrations/028_legal_documents_extend.sql
Benjamin Admin b7c1a5da1a
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 36s
CI / test-python-backend-compliance (push) Successful in 31s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 18s
feat: Consent-Service Module nach Compliance migriert (DSR, E-Mail-Templates, Legal Docs, Banner)
5-Phasen-Migration: Go consent-service Proxies durch native Python/FastAPI ersetzt.

Phase 1 — DSR (Betroffenenrechte): 6 Tabellen, 30 Endpoints, Frontend-API umgestellt
Phase 2 — E-Mail-Templates: 5 Tabellen, 20 Endpoints, neues Frontend, SDK_STEPS erweitert
Phase 3 — Legal Documents Extension: User Consents, Audit Log, Cookie-Kategorien
Phase 4 — Banner Consent: Device-Consents, Site-Configs, Kategorien, Vendors
Phase 5 — Cleanup: DSR-Proxy aus main.py entfernt, Frontend-URLs aktualisiert

148 neue Tests (50 + 47 + 26 + 25), alle bestanden.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 00:36:24 +01:00

70 lines
3.7 KiB
SQL

-- =========================================================
-- Migration 028: Legal Documents Extension
-- User Consents, Consent Audit Log, Cookie Categories
-- =========================================================
-- compliance_user_consents: End-User Consent-Records
CREATE TABLE IF NOT EXISTS compliance_user_consents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL,
user_id TEXT NOT NULL,
document_id UUID NOT NULL REFERENCES compliance_legal_documents(id) ON DELETE CASCADE,
document_version_id UUID REFERENCES compliance_legal_document_versions(id) ON DELETE SET NULL,
document_type TEXT NOT NULL,
consented BOOLEAN NOT NULL DEFAULT TRUE,
ip_address TEXT,
user_agent TEXT,
consented_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
withdrawn_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_user_consents_tenant ON compliance_user_consents(tenant_id);
CREATE INDEX IF NOT EXISTS idx_user_consents_user ON compliance_user_consents(user_id);
CREATE INDEX IF NOT EXISTS idx_user_consents_doc ON compliance_user_consents(document_id);
CREATE INDEX IF NOT EXISTS idx_user_consents_type ON compliance_user_consents(document_type);
-- compliance_consent_audit_log: Immutable Audit-Trail
CREATE TABLE IF NOT EXISTS compliance_consent_audit_log (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL,
action TEXT NOT NULL, -- consent_given|consent_withdrawn|consent_checked|document_published
entity_type TEXT NOT NULL, -- user_consent|legal_document|cookie_category
entity_id UUID,
user_id TEXT,
details JSONB DEFAULT '{}',
ip_address TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_consent_audit_tenant ON compliance_consent_audit_log(tenant_id);
CREATE INDEX IF NOT EXISTS idx_consent_audit_action ON compliance_consent_audit_log(action);
CREATE INDEX IF NOT EXISTS idx_consent_audit_entity ON compliance_consent_audit_log(entity_type, entity_id);
CREATE INDEX IF NOT EXISTS idx_consent_audit_created ON compliance_consent_audit_log(created_at);
-- compliance_cookie_categories: Cookie-Kategorien fuer Banner
CREATE TABLE IF NOT EXISTS compliance_cookie_categories (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL,
name_de TEXT NOT NULL,
name_en TEXT,
description_de TEXT,
description_en TEXT,
is_required BOOLEAN NOT NULL DEFAULT FALSE,
sort_order INTEGER NOT NULL DEFAULT 0,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_cookie_cats_tenant ON compliance_cookie_categories(tenant_id);
-- Default Cookie-Kategorien
INSERT INTO compliance_cookie_categories (tenant_id, name_de, name_en, description_de, description_en, is_required, sort_order)
VALUES
('9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'::UUID, 'Notwendig', 'Necessary', 'Technisch notwendige Cookies fuer den Betrieb der Website.', 'Technically necessary cookies for website operation.', TRUE, 0),
('9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'::UUID, 'Funktional', 'Functional', 'Cookies fuer erweiterte Funktionalitaet und Personalisierung.', 'Cookies for enhanced functionality and personalization.', FALSE, 10),
('9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'::UUID, 'Analyse', 'Analytics', 'Cookies zur Analyse der Websitenutzung.', 'Cookies for analyzing website usage.', FALSE, 20),
('9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'::UUID, 'Marketing', 'Marketing', 'Cookies fuer personalisierte Werbung.', 'Cookies for personalized advertising.', FALSE, 30)
ON CONFLICT DO NOTHING;