2026-07-04 20:28:07 +02:00
|
|
|
-- Dev/CI: pytest-Artefakte entfernen (idempotent, sicher mehrfach ausführbar).
|
|
|
|
|
-- Nur in Nicht-Prod-Umgebungen (Dateiname *.dev.sql).
|
|
|
|
|
|
2026-07-04 20:38:49 +02:00
|
|
|
-- Reparatur: ungültige Human-Actors (user_id NULL verletzt CHECK constraint)
|
|
|
|
|
DELETE FROM actors WHERE actor_type = 'human' AND user_id IS NULL;
|
|
|
|
|
|
2026-07-04 20:28:07 +02:00
|
|
|
-- 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$');
|
|
|
|
|
|
|
|
|
|
DELETE FROM tenant_memberships
|
|
|
|
|
WHERE user_id IN (SELECT id FROM users WHERE email ~* '@example\.com$');
|
|
|
|
|
|
|
|
|
|
DELETE FROM sessions
|
|
|
|
|
WHERE user_id IN (SELECT id FROM users WHERE email ~* '@example\.com$');
|
|
|
|
|
|
|
|
|
|
DELETE FROM audit_log
|
|
|
|
|
WHERE user_id IN (SELECT id FROM users WHERE email ~* '@example\.com$');
|
|
|
|
|
|
|
|
|
|
DELETE FROM users WHERE email ~* '@example\.com$';
|
|
|
|
|
|
|
|
|
|
-- Verwaiste pytest-Tenants (Factory-Slug t-{10 hex}), ohne Memberships
|
|
|
|
|
DELETE FROM actors a
|
|
|
|
|
USING tenants t
|
|
|
|
|
WHERE a.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
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
DELETE FROM tenants t
|
|
|
|
|
WHERE t.slug ~ '^t-[a-f0-9]{10}$'
|
|
|
|
|
AND NOT EXISTS (
|
|
|
|
|
SELECT 1 FROM tenant_memberships tm WHERE tm.tenant_id = t.id
|
|
|
|
|
);
|