From a34a61458e64e2bdaa6b2de95d972db6400c746a Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 5 Jul 2026 06:17:56 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Cleanup-Seed=20l=C3=B6scht=20Initiatives?= =?UTF-8?q?=20vor=20pytest-Actors=20(FK=20RESTRICT).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seed_001_cleanup_pytest_artifacts.dev.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/seeds/seed_001_cleanup_pytest_artifacts.dev.sql b/backend/seeds/seed_001_cleanup_pytest_artifacts.dev.sql index c52b7fa..5de90ba 100644 --- a/backend/seeds/seed_001_cleanup_pytest_artifacts.dev.sql +++ b/backend/seeds/seed_001_cleanup_pytest_artifacts.dev.sql @@ -4,6 +4,21 @@ -- Reparatur: ungültige Human-Actors (user_id NULL verletzt CHECK constraint) DELETE FROM actors WHERE actor_type = 'human' AND user_id IS NULL; +-- AP0.5: Vorhaben/Maßnahmen pytest-Artefakte vor Actor-Löschung entfernen +-- (initiatives.owner_actor_id → actors ON DELETE RESTRICT) +DELETE FROM initiatives +WHERE owner_actor_id IN ( + SELECT id FROM actors WHERE user_id IN (SELECT id FROM users WHERE email ~* '@example\.com$') +); + +DELETE FROM initiatives i +USING tenants t +WHERE i.tenant_id = t.id + AND t.slug ~ '^t-[a-f0-9]{10}$' + AND NOT EXISTS ( + SELECT 1 FROM tenant_memberships tm WHERE tm.tenant_id = t.id + ); + -- Abhängigkeiten vor User-Löschung (human actors: user_id NOT NULL constraint) DELETE FROM actors WHERE user_id IN (SELECT id FROM users WHERE email ~* '@example\.com$');