-- Tighten the bookmarks uniqueness for manga-level bookmarks.
--
-- The 0001 UNIQUE constraint is (user_id, manga_id, chapter_id), but
-- PostgreSQL treats NULL as distinct under NULLS DISTINCT (the default),
-- so two manga-level bookmarks for the same (user, manga) were both
-- allowed. The partial index below blocks that exact case, while letting
-- a manga-level bookmark coexist with chapter-level bookmarks for the
-- same manga (which is the intended UX).

CREATE UNIQUE INDEX bookmarks_user_manga_no_chapter_uniq
    ON bookmarks (user_id, manga_id)
    WHERE chapter_id IS NULL;
