-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path0058_drop_old_stats.sql
137 lines (108 loc) · 3.51 KB
/
0058_drop_old_stats.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--
-- NOTE: THIS MUST ONLY BE RUN AFTER THE NEW API IS DEPLOYED.
--
-- Drop the podcasts stats indexes
DO $$
DECLARE
index_name TEXT;
BEGIN
FOR index_name IN
SELECT indexname
FROM pg_indexes
WHERE tablename = 'podcasts'
AND (
indexdef ILIKE '%pastHourTotalUniquePageviews%'
OR indexdef ILIKE '%pastDayTotalUniquePageviews%'
OR indexdef ILIKE '%pastWeekTotalUniquePageviews%'
OR indexdef ILIKE '%pastMonthTotalUniquePageviews%'
OR indexdef ILIKE '%pastYearTotalUniquePageviews%'
OR indexdef ILIKE '%pastAllTimeTotalUniquePageviews%'
)
LOOP
EXECUTE format('DROP INDEX IF EXISTS %I;', index_name);
END LOOP;
END $$;
-- Drop the episodes stats indexes
DO $$
DECLARE
index_name TEXT;
BEGIN
FOR index_name IN
SELECT indexname
FROM pg_indexes
WHERE tablename = 'episodes'
AND (
indexdef ILIKE '%pastHourTotalUniquePageviews%'
OR indexdef ILIKE '%pastDayTotalUniquePageviews%'
OR indexdef ILIKE '%pastWeekTotalUniquePageviews%'
OR indexdef ILIKE '%pastMonthTotalUniquePageviews%'
OR indexdef ILIKE '%pastYearTotalUniquePageviews%'
OR indexdef ILIKE '%pastAllTimeTotalUniquePageviews%'
)
LOOP
EXECUTE format('DROP INDEX IF EXISTS %I;', index_name);
END LOOP;
END $$;
-- Drop the mediaRefs stats indexes
DO $$
DECLARE
index_name TEXT;
BEGIN
FOR index_name IN
SELECT indexname
FROM pg_indexes
WHERE tablename = 'mediaRefs'
AND (
indexdef ILIKE '%pastHourTotalUniquePageviews%'
OR indexdef ILIKE '%pastDayTotalUniquePageviews%'
OR indexdef ILIKE '%pastWeekTotalUniquePageviews%'
OR indexdef ILIKE '%pastMonthTotalUniquePageviews%'
OR indexdef ILIKE '%pastYearTotalUniquePageviews%'
OR indexdef ILIKE '%pastAllTimeTotalUniquePageviews%'
)
LOOP
EXECUTE format('DROP INDEX IF EXISTS %I;', index_name);
END LOOP;
END $$;
-- Drop old podcast stats columns
ALTER TABLE podcasts
DROP COLUMN "pastHourTotalUniquePageviews";
ALTER TABLE podcasts
DROP COLUMN "pastDayTotalUniquePageviews";
ALTER TABLE podcasts
DROP COLUMN "pastWeekTotalUniquePageviews";
ALTER TABLE podcasts
DROP COLUMN "pastMonthTotalUniquePageviews";
ALTER TABLE podcasts
DROP COLUMN "pastYearTotalUniquePageviews";
ALTER TABLE podcasts
DROP COLUMN "pastAllTimeTotalUniquePageviews";
-- Drop old episode stats columns
-- First drop the dependent materialized view
DROP MATERIALIZED VIEW "episodes_most_recent";
ALTER TABLE episodes
DROP COLUMN "pastHourTotalUniquePageviews";
ALTER TABLE episodes
DROP COLUMN "pastDayTotalUniquePageviews";
ALTER TABLE episodes
DROP COLUMN "pastWeekTotalUniquePageviews";
ALTER TABLE episodes
DROP COLUMN "pastMonthTotalUniquePageviews";
ALTER TABLE episodes
DROP COLUMN "pastYearTotalUniquePageviews";
ALTER TABLE episodes
DROP COLUMN "pastAllTimeTotalUniquePageviews";
-- Drop old mediaRefs stats columns
DROP MATERIALIZED VIEW "mediaRefs_videos";
ALTER TABLE "mediaRefs"
DROP COLUMN "pastHourTotalUniquePageviews";
ALTER TABLE "mediaRefs"
DROP COLUMN "pastDayTotalUniquePageviews";
ALTER TABLE "mediaRefs"
DROP COLUMN "pastWeekTotalUniquePageviews";
ALTER TABLE "mediaRefs"
DROP COLUMN "pastMonthTotalUniquePageviews";
ALTER TABLE "mediaRefs"
DROP COLUMN "pastYearTotalUniquePageviews";
ALTER TABLE "mediaRefs"
DROP COLUMN "pastAllTimeTotalUniquePageviews";