33 lines
1.0 KiB
MySQL
33 lines
1.0 KiB
MySQL
|
|
-- Dev/CI: pytest-Artefakte entfernen (idempotent, sicher mehrfach ausführbar).
|
||
|
|
-- Nur in Nicht-Prod-Umgebungen (Dateiname *.dev.sql).
|
||
|
|
|
||
|
|
-- 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
|
||
|
|
);
|