-- Remove duplicate participants (same sports_season_id + name), keeping the oldest (lowest created_at)
DELETE FROM "participants"
WHERE id IN (
  SELECT id FROM (
    SELECT id,
           ROW_NUMBER() OVER (PARTITION BY sports_season_id, name ORDER BY created_at ASC) AS rn
    FROM "participants"
  ) ranked
  WHERE rn > 1
);
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "participants_sports_season_name_unique" ON "participants" USING btree ("sports_season_id","name");
