Files
craftvia/prisma/migrations/20260811140000_webauthn_identity/migration.sql
T
msolarczekandClaude Opus 5 c8e6f30a27
CI / build-and-check (push) Canceled after 0s
CI / audit (push) Canceled after 0s
CI / sbom (push) Canceled after 0s
Basis: Certvia dev@a48c5fb als Fundament für Craftvia
Unveränderter Stand von certvia/dev (a48c5fb) plus Craftvia-Spezifikation
und Brandbook unter docs/craftvia/. ISMS-Module werden im Folgecommit entfernt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 11:05:39 +02:00

36 lines
1.7 KiB
SQL

-- ============================================================================
-- WS4b (Option C) — WebAuthn/Passkeys von der Mitgliedschaft auf die GLOBALE Identity
-- ============================================================================
-- Passkeys sind identitäts-, nicht mandantengebunden. Die Tabelle verliert daher
-- tenant_id + RLS und verweist künftig auf `identities`. `webauthn_credentials` ist
-- damit ein GLOBALES Modell (nicht mehr in TENANT_MODELS).
--
-- Reihenfolge: erst RLS/Policy abbauen (die Policy referenziert tenant_id), dann die
-- Spalten umbauen. identity_id ist NOT NULL — die Migration läuft auf einer leeren
-- Tabelle (im Seed werden keine Passkeys angelegt; Bestand = Testdaten).
-- ============================================================================
-- RLS/Policy entfernen (war über webauthn_credentials-Migration + rls_enforce gesetzt).
ALTER TABLE "webauthn_credentials" DISABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS tenant_isolation ON "webauthn_credentials";
-- DropForeignKey
ALTER TABLE "webauthn_credentials" DROP CONSTRAINT "webauthn_credentials_user_id_fkey";
-- DropIndex
DROP INDEX "webauthn_credentials_tenant_id_idx";
-- DropIndex
DROP INDEX "webauthn_credentials_user_id_idx";
-- AlterTable: tenant_id/user_id → identity_id
ALTER TABLE "webauthn_credentials" DROP COLUMN "tenant_id",
DROP COLUMN "user_id",
ADD COLUMN "identity_id" TEXT NOT NULL;
-- CreateIndex
CREATE INDEX "webauthn_credentials_identity_id_idx" ON "webauthn_credentials"("identity_id");
-- AddForeignKey
ALTER TABLE "webauthn_credentials" ADD CONSTRAINT "webauthn_credentials_identity_id_fkey" FOREIGN KEY ("identity_id") REFERENCES "identities"("id") ON DELETE CASCADE ON UPDATE CASCADE;