aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/db/migrations/005_add_guid_index.sql
diff options
context:
space:
mode:
Diffstat (limited to 'backend/db/migrations/005_add_guid_index.sql')
-rw-r--r--backend/db/migrations/005_add_guid_index.sql10
1 files changed, 10 insertions, 0 deletions
diff --git a/backend/db/migrations/005_add_guid_index.sql b/backend/db/migrations/005_add_guid_index.sql
new file mode 100644
index 0000000..e3625ee
--- /dev/null
+++ b/backend/db/migrations/005_add_guid_index.sql
@@ -0,0 +1,10 @@
+-- Add index on guid for deduplication
+CREATE INDEX IF NOT EXISTS idx_articles_guid ON articles(guid);
+
+-- Remove duplicate articles by guid, keeping only the one with the smallest id
+DELETE FROM articles
+WHERE id NOT IN (
+ SELECT MIN(id)
+ FROM articles
+ GROUP BY guid
+);