-- 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;