Add indexes for favorite de-duplication
This commit is contained in:
3
migrations/2025-12-17-230100_unique_favorites/down.sql
Normal file
3
migrations/2025-12-17-230100_unique_favorites/down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- Rollback unique constraint on favorites
|
||||
|
||||
DROP INDEX IF EXISTS idx_favorites_unique;
|
||||
12
migrations/2025-12-17-230100_unique_favorites/up.sql
Normal file
12
migrations/2025-12-17-230100_unique_favorites/up.sql
Normal file
@@ -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);
|
||||
Reference in New Issue
Block a user