DELETE FROM watchers
WHERE rowid NOT IN (
    SELECT MIN(rowid)
    FROM watchers
    GROUP BY user_id, document_id, folder_path
);

CREATE UNIQUE INDEX IF NOT EXISTS idx_watchers_user_document_unique
ON watchers(user_id, document_id)
WHERE document_id IS NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS idx_watchers_user_folder_unique
ON watchers(user_id, folder_path)
WHERE folder_path IS NOT NULL;
