From 7ddc2dec6424040c2672602af33483e21a694fbd Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 17 Dec 2025 22:31:16 -0500 Subject: [PATCH] Add indexes for favorite de-duplication --- .../2025-12-17-230100_unique_favorites/down.sql | 3 +++ migrations/2025-12-17-230100_unique_favorites/up.sql | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 migrations/2025-12-17-230100_unique_favorites/down.sql create mode 100644 migrations/2025-12-17-230100_unique_favorites/up.sql diff --git a/migrations/2025-12-17-230100_unique_favorites/down.sql b/migrations/2025-12-17-230100_unique_favorites/down.sql new file mode 100644 index 0000000..b42819b --- /dev/null +++ b/migrations/2025-12-17-230100_unique_favorites/down.sql @@ -0,0 +1,3 @@ +-- Rollback unique constraint on favorites + +DROP INDEX IF EXISTS idx_favorites_unique; diff --git a/migrations/2025-12-17-230100_unique_favorites/up.sql b/migrations/2025-12-17-230100_unique_favorites/up.sql new file mode 100644 index 0000000..b123617 --- /dev/null +++ b/migrations/2025-12-17-230100_unique_favorites/up.sql @@ -0,0 +1,12 @@ +-- Add unique constraint to prevent duplicate favorites per user + +-- First, remove any existing duplicates (keep the oldest one) +DELETE FROM favorites +WHERE rowid NOT IN ( + SELECT MIN(rowid) + FROM favorites + GROUP BY userid, path +); + +-- Add unique index to enforce constraint +CREATE UNIQUE INDEX idx_favorites_unique ON favorites(userid, path);