Skip to content

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

@tovmeod

Description

@tovmeod

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions