-- Migration: Fix wishlist_id unique index to allow multiple users
-- Date: 2026-01-30
--
-- This migration fixes the unique index on wishlist_id to allow multiple users
-- to create tasks for the same wishlist item. The old index only checked wishlist_id,
-- but now we need a composite unique index on (wishlist_id, user_id).

-- Drop the old unique index that only checked wishlist_id
DROP INDEX IF EXISTS idx_tasks_wishlist_id_unique;

-- Create a new composite unique index on (wishlist_id, user_id)
-- This allows multiple users to have tasks for the same wishlist item,
-- but prevents the same user from having multiple tasks for the same wishlist item
CREATE UNIQUE INDEX idx_tasks_wishlist_id_user_id_unique 
ON tasks(wishlist_id, user_id) 
WHERE wishlist_id IS NOT NULL AND deleted = FALSE;
