-- Migration: art9_consent_log -- DSGVO Art. 9 Compliance — Mail-Auto-Delete-Einwilligung -- -- 1. Drei additiv hinzugefügte Spalten in mail_connections: -- - consent_at TIMESTAMPTZ NULL → wann explizit eingewilligt wurde -- - consent_version TEXT NULL → Versionierter Einwilligungs-Text -- - consent_ip_address TEXT NULL → IP zum Beweiszweck (Art. 7 Abs. 1 DSGVO) -- -- Bestandsrows erhalten DEFAULT NULL (= "Re-Consent pending"). -- KEIN automatisches Backfill auf now() — das wäre rechtlich falsch. -- -- 2. Neue Tabelle consent_logs (append-only Audit-Trail): -- Jede Einwilligung und jeder Widerruf landet hier. -- Niemals löschen — nur archivieren. -- -- Breaking-change: NONE. Alle neuen Spalten sind nullable. -- Deploy: pnpm prisma migrate deploy (via GitHub Actions Pipeline) -- ── 1. mail_connections: Art. 9 Consent-Spalten ──────────────────────────── ALTER TABLE "rebreak"."mail_connections" ADD COLUMN "consent_at" TIMESTAMPTZ, ADD COLUMN "consent_version" TEXT, ADD COLUMN "consent_ip_address" TEXT; -- Kein UPDATE/Backfill: NULL = "Re-Consent pending" (semantisch korrekt). -- ── 2. consent_logs: Append-only Audit-Tabelle ───────────────────────────── CREATE TABLE "rebreak"."consent_logs" ( "id" TEXT NOT NULL, "user_id" UUID NOT NULL, "consent_type" TEXT NOT NULL, "consent_version" TEXT NOT NULL, "consent_at" TIMESTAMPTZ NOT NULL, "ip_address" TEXT, "user_agent" TEXT, "mail_connection_id" UUID, "revoked_at" TIMESTAMPTZ, "revoke_reason" TEXT, CONSTRAINT "consent_logs_pkey" PRIMARY KEY ("id") ); CREATE INDEX "consent_logs_user_id_consent_type_idx" ON "rebreak"."consent_logs" ("user_id", "consent_type");