fix(scheduling): extend AnonymizeStaleGuestAccounts with additional field scrubbing

AnonymizeStaleGuestAccounts now additionally scrubs profile_pic_url (NULL), referral_code (NULL), notes (NULL), and data_retention_consent (FALSE) for stale guest accounts. Previously only scrubbed name, email, phone, and date_of_birth. Ensures comprehensive PII removal for guests with no active/pending bookings and last booking over 6 months old.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-05 12:12:38 +01:00
co-authored by Sisyphus
parent 40840c0458
commit b460c2ec20
+11 -7
View File
@@ -368,13 +368,17 @@ func CleanupOldReservations(ctx context.Context) error {
// Active/pending bookings are excluded so the salon can still contact the guest. // Active/pending bookings are excluded so the salon can still contact the guest.
func AnonymizeStaleGuestAccounts(ctx context.Context) error { func AnonymizeStaleGuestAccounts(ctx context.Context) error {
_, err := db.DB.Exec(ctx, ` _, err := db.DB.Exec(ctx, `
UPDATE users SET UPDATE users SET
n_first_name = 'Guest', n_first_name = 'Guest',
n_last_name = 'Anonymized', n_last_name = 'Anonymized',
email = 'anon-' || id || '@anon.invalid', email = 'anon-' || id || '@anon.invalid',
phone = '000000000000', phone = '000000000000',
date_of_birth = '1900-01-01', date_of_birth = '1900-01-01',
updated_at = NOW() profile_pic_url = NULL,
referral_code = NULL,
notes = NULL,
data_retention_consent = FALSE,
updated_at = NOW()
WHERE account_role = 'guest' WHERE account_role = 'guest'
AND id NOT IN ( AND id NOT IN (
SELECT user_id FROM bookings WHERE status IN ('pending', 'confirmed') SELECT user_id FROM bookings WHERE status IN ('pending', 'confirmed')