Skip to content

Commit 3d5ab24

Browse files
committed
fix: use publishedAt timestamp instead of version_id for deduplication
version_id is a UUID, not an incrementing ID, so we need to use publishedAt timestamp to determine which duplicate to keep
1 parent 99b63b1 commit 3d5ab24

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

internal/database/migrations/008_clean_invalid_data.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ WHERE value->>'status' IS NOT NULL
131131
AND value->>'status' NOT IN ('active', 'deprecated', 'deleted');
132132

133133
-- Remove duplicate name+version combinations
134-
-- Keep the one with the highest version_id (most recently added)
134+
-- Keep the one with the most recent publishedAt date
135135
DELETE FROM servers s1
136136
WHERE EXISTS (
137137
SELECT 1 FROM servers s2
138138
WHERE s2.value->>'name' = s1.value->>'name'
139139
AND s2.value->>'version' = s1.value->>'version'
140-
AND s2.version_id > s1.version_id
140+
AND (s2.value->>'publishedAt')::timestamp > (s1.value->>'publishedAt')::timestamp
141141
);
142142

143143
-- Verify the operations completed as expected

0 commit comments

Comments
 (0)