← back to Animals
migrations/007_events_dedupe_with_title.sql
16 lines
-- 007_events_dedupe_with_title.sql
-- Fixes the ON CONFLICT key mismatch flagged by codex on 2026-05-01.
--
-- The original idx_events_dedupe (source, source_url, start_at) collided for
-- AKC/UKC imports where source_url is the shared search/results page —
-- multiple distinct events on the same date silently overwrote each other.
-- Adding `title` to the unique key so distinct events on the same source/date
-- survive.
--
-- Idempotent: drops the old index if present, recreates the new one.
DROP INDEX IF EXISTS idx_events_dedupe;
CREATE UNIQUE INDEX IF NOT EXISTS idx_events_dedupe
ON events (source, source_url, start_at, title);