DB scripts and migrations

This commit is contained in:
2024-12-09 19:54:00 +02:00
parent 7a36614232
commit 6cf507bdc9
5 changed files with 66 additions and 54 deletions

22
db/fix-url-ports.sql Normal file
View File

@@ -0,0 +1,22 @@
-- Here's an SQL script that will find and remove snapshots without port numbers
-- when there exists a duplicate with the default port 1965.
-- Before running this DELETE though, you might want to
-- verify the matches first with this SELECT:
WITH duplicates AS (
SELECT s1.id as id_without_port, s2.id as id_with_port, s1.url as url_without_port, s2.url as url_with_port
FROM snapshots s1
JOIN snapshots s2
ON s2.url = s1.url || ':1965'
)
SELECT * FROM duplicates;
-- Now delete them for real:
WITH duplicates AS (
SELECT s1.id as id_without_port, s2.id as id_with_port, s1.url as url_without_port, s2.url as url_with_port
FROM snapshots s1
JOIN snapshots s2
ON s2.url = s1.url || ':1965'
)
DELETE FROM snapshots
WHERE id IN (SELECT id_without_port FROM duplicates);