-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanup-redirects.sql
41 lines (39 loc) · 1021 Bytes
/
cleanup-redirects.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- manual redirects which duplicate auto redirects
WITH auto_redirects AS (
SELECT DISTINCT
(SELECT effname FROM metapackages WHERE id = old.project_id) AS oldname,
(SELECT effname FROM metapackages WHERE id = new.project_id) AS newname
FROM project_redirects AS old INNER JOIN project_redirects AS new USING(repository_id, trackname)
WHERE
NOT old.is_actual AND new.is_actual
)
DELETE
FROM project_redirects_manual
WHERE EXISTS (
SELECT *
FROM auto_redirects
WHERE
auto_redirects.oldname = project_redirects_manual.oldname AND
auto_redirects.newname = project_redirects_manual.newname
)
;
-- projects that never existed
DELETE
FROM project_redirects_manual
WHERE NOT EXISTS (
SELECT *
FROM metapackages
WHERE
metapackages.effname = project_redirects_manual.newname AND metapackages.num_repos > 0
)
;
-- half-redirects are useless
DELETE
FROM project_redirects
WHERE project_id IN(
SELECT
project_id
FROM project_redirects
GROUP BY project_id
HAVING count(*) = 1
);