forked from Dri0m/flashpoint-submission-system
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpgdb-utils.sql
122 lines (98 loc) · 3.21 KB
/
pgdb-utils.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
-- Disable and enable triggers
SET session_replication_role = replica;
SET session_replication_role = DEFAULT;
-- Rebuild platform strings
---- Dry Run
SELECT COUNT(*) as rows_that_would_change
FROM game
LEFT JOIN (
SELECT game_id,
string_agg((SELECT primary_alias FROM platform WHERE id = p.platform_id), '; ') AS new_platforms_str
FROM game_platforms_platform p
GROUP BY game_id
) subquery ON game.id = subquery.game_id
WHERE (game.platforms_str IS DISTINCT FROM subquery.new_platforms_str
OR (game.platforms_str IS NULL AND subquery.new_platforms_str IS NOT NULL)
OR (game.platforms_str IS NOT NULL AND subquery.new_platforms_str IS NULL));
--- Live Run
UPDATE game
SET platforms_str = new_platforms_str,
reason = 'Rebuild Platforms String',
user_id = 810112564787675166
FROM (
SELECT id,
string_agg((SELECT primary_alias FROM platform WHERE id = p.platform_id), '; ') AS new_platforms_str
FROM game
LEFT JOIN game_platforms_platform p ON p.game_id = game.id
GROUP BY game.id
) subquery
WHERE game.id = subquery.id
AND (game.platforms_str IS DISTINCT FROM subquery.new_platforms_str
OR (game.platforms_str IS NULL AND subquery.new_platforms_str IS NOT NULL)
OR (game.platforms_str IS NOT NULL AND subquery.new_platforms_str IS NULL));
-- Rebuild tag strings
-- TODO: Make sure to only update necessary rows
UPDATE game
SET tags_str = coalesce(
(
SELECT string_agg(
(SELECT primary_alias FROM tag WHERE id = t.tag_id), '; '
)
FROM game_tags_tag t
WHERE t.game_id = game.id
), ''
) WHERE 1=1
-- Update app paths
---- Dry Run
SELECT COUNT(*) as rows_that_would_change
FROM game_data
WHERE application_path = 'app_path_here';
SELECT COUNT(*) as rows_that_would_change
FROM game
WHERE application_path = 'app_path_here';
---- Live Run
UPDATE game_data
SET application_path = 'new_app_path'
WHERE application_path = 'app_path_here';
UPDATE game
SET reason = 'Update Application Path',
user_id = 810112564787675166
WHERE id IN (
SELECT game_id FROM game_data
WHERE application_path = 'new_app_path'
);
UPDATE game
SET application_path = 'new_app_path',
reason = 'Update Application Path',
user_id = 810112564787675166
WHERE application_path = 'app_path_here';
-- Update Launch Commands
---- Dry Run
SELECT COUNT(*) as rows_that_would_change
FROM game_data
WHERE application_path = 'app_path_here'
AND launch_command NOT LIKE 'prefix%'
AND launch_command LIKE 'http%';
SELECT COUNT(*) as rows_that_would_change
FROM game
WHERE application_path = 'app_path_here'
AND launch_command NOT LIKE 'prefix%'
AND launch_command LIKE 'http%';
---- Live Run
UPDATE game_data
SET launch_command = concat('prefix ', launch_command)
WHERE application_path = 'app_path_here';
UPDATE game
SET reason = 'Update Launch Command',
user_id = 810112564787675166
WHERE id IN (
SELECT game_id FROM game_data
WHERE application_path = 'app_path_here'
AND launch_command LIKE 'prefix%'
);
UPDATE game
SET launch_command = concat('prefix ', launch_command),
reason = 'Update Launch Command',
user_id = 810112564787675166
WHERE application_path = 'app_path_here'
AND launch_command LIKE 'prefix%';