Files
typo3-13/.ddev/anonymize-db.sql
frommeandClaude Opus 5.5 b428ce9086 feat: ddev anonymize-db removes personal data from production dumps
Runs automatically after every `ddev import-db`. Drops all zzz_deleted_
tables (renamed in production but still holding their data, e.g. the
retired address check and form answers), replaces names and emails of
backend and frontend users, sets every password to the local dev
password "password" and clears reset tokens and MFA secrets. Sessions,
record locks, CSP reports and logs are emptied (IP addresses, user
agents). Usernames stay, so everybody logs in locally as their own user.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 10:13:02 +01:00

45 lines
1.8 KiB
SQL

-- Removes personal data from a production dump. Run by `ddev anonymize-db`, which ddev also
-- runs after every `ddev import-db`. Safe to run more than once.
-- @devPasswordHash is set by the command before this file runs.
-- Tables renamed by the database analyzer in production keep their data until dropped there
SET @zzzTables = (
SELECT GROUP_CONCAT('`', table_name, '`')
FROM information_schema.tables
WHERE table_schema = DATABASE() AND table_name LIKE 'zzz\_deleted\_%'
);
SET @dropZzzTables = IF(@zzzTables IS NULL, 'DO 0', CONCAT('DROP TABLE ', @zzzTables));
PREPARE dropZzzTables FROM @dropZzzTables;
EXECUTE dropZzzTables;
DEALLOCATE PREPARE dropZzzTables;
-- Usernames stay, so everybody logs in locally as their own user (with the dev password)
UPDATE be_users SET
realName = IF('' = realName, '', CONCAT('BE User ', uid)),
email = IF('' = email, '', CONCAT('be-user-', uid, '@example.invalid')),
password = @devPasswordHash,
password_reset_token = '',
mfa = NULL;
UPDATE fe_users SET
username = CONCAT('fe-user-', uid),
password = @devPasswordHash,
name = IF('' = name, '', CONCAT('FE User ', uid)),
first_name = IF('' = first_name, '', 'Vorname'),
middle_name = '',
last_name = IF('' = last_name, '', CONCAT('Nachname ', uid)),
address = IF('' = address, '', 'Musterstraße 1'),
telephone = IF('' = telephone, '', '0000 000000'),
email = IF('' = email, '', CONCAT('fe-user-', uid, '@example.invalid')),
zip = IF('' = zip, '', '00000'),
city = IF('' = city, '', 'Musterstadt');
-- Sessions, locks, reports and logs: IP addresses, user agents, user data
TRUNCATE be_sessions;
TRUNCATE fe_sessions;
TRUNCATE sys_lockedrecords;
TRUNCATE sys_http_report;
TRUNCATE sys_log;
TRUNCATE tx_epproducts_log;
TRUNCATE tx_epevents_log;