#1038·whatsmeow

whatsmeow_privacy_tokens table missing foreign key constraint - orphan data on device deletion

Author: tovmeodCreated Dec 16, 2025Updated Sep 20, 2026

The whatsmeow_privacy_tokens table has an our_jid column but no foreign key constraint to whatsmeow_device(jid). This means when a device is deleted (re-pairing, logout, etc.), privacy tokens remain as orphaned data.

All other tables with our_jid have the FK constraint with cascade delete

Suggested fix

Add FK constraint to whatsmeow_privacy_tokens:

ALTER TABLE whatsmeow_privacy_tokens ADD CONSTRAINT whatsmeow_privacy_tokens_device_fk FOREIGN KEY (our_jid) REFERENCES whatsmeow_device(jid) ON DELETE CASCADE ON UPDATE CASCADE;