-- Deduplicate: keep a single row per user (latest expiry, then stable tie-breaker).
DELETE FROM "public"."Session" s
WHERE s.ctid NOT IN (
  SELECT DISTINCT ON (s2."userId") s2.ctid
  FROM "public"."Session" s2
  ORDER BY s2."userId", s2."expires" DESC, s2."sessionToken" DESC
);

-- CreateIndex
CREATE UNIQUE INDEX "Session_userId_key" ON "public"."Session"("userId");
