You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"ALTER TABLE password_resets ALTER COLUMN used_on TYPE timestamp with time zone USING (CASE WHEN used_on IS NOT NULL THEN CURRENT_TIMESTAMP ELSE NULL END)");
15
+
"ALTER TABLE password_resets ALTER COLUMN used_on TYPE timestamp with time zone USING (CASE WHEN used_on IS NOT NULL THEN CURRENT_TIMESTAMP ELSE NULL END);");
SPLIT_PART(u.password_hash, ':', 1) AS password_hash_type,
18
+
u.created_at,
19
+
u.email_activated,
20
+
u.roles,
21
+
(SELECT COUNT(*) FROM api_tokens ato WHERE ato.user_id = u.id) AS api_token_count,
22
+
(SELECT COUNT(*) FROM password_resets pre WHERE pre.user_id = u.id) AS password_reset_count,
23
+
(SELECT COUNT(*) FROM shocker_shares ssh WHERE ssh.shared_with = u.id) AS shocker_share_count,
24
+
(SELECT COUNT(*) FROM shocker_shares_links ssl WHERE ssl.owner_id = u.id) AS shocker_share_link_count,
25
+
(SELECT COUNT(*) FROM users_email_changes uec WHERE uec.user_id = u.id) AS email_change_request_count,
26
+
(SELECT COUNT(*) FROM users_name_changes unc WHERE unc.user_id = u.id) AS name_change_request_count,
27
+
(SELECT COUNT(*) FROM users_activation uac WHERE uac.user_id = u.id) AS user_activation_count,
28
+
(SELECT COUNT(*) FROM devices dev WHERE dev.owner = u.id) AS device_count,
29
+
(SELECT COUNT(*) FROM devices dev JOIN shockers sck ON dev.id = sck.device WHERE dev.owner = u.id) AS shocker_count,
30
+
(SELECT COUNT(*) FROM devices dev JOIN shockers sck ON dev.id = sck.device JOIN shocker_control_logs scl ON scl.shocker_id = sck.id WHERE dev.owner = u.id) AS shocker_control_log_count
-- Drop the view temporarily to modify the underlying table
16
-
DROP VIEW admin_users_view;
17
-
18
43
-- Add the roles column as a text array to replace the rank enum
19
44
ALTER TABLE users ADD roles text[] NOT NULL DEFAULT ARRAY[]::text[];
20
45
@@ -40,41 +65,21 @@ UPDATE users
40
65
-- Update the roles column to use the new role_type enum array
41
66
ALTER TABLE users ALTER COLUMN roles SET DEFAULT ARRAY[]::role_type[];
42
67
ALTER TABLE users ALTER COLUMN roles TYPE role_type[] USING CAST(roles as role_type[]);
43
-
44
-
-- Recreate the admin_users_view to reflect the new roles structure
45
-
CREATE VIEW admin_users_view AS
46
-
SELECT
47
-
u.id,
48
-
u.name,
49
-
u.email,
50
-
SPLIT_PART(u.password_hash, ':', 1) AS password_hash_type,
51
-
u.created_at,
52
-
u.email_activated,
53
-
u.roles,
54
-
(SELECT COUNT(*) FROM api_tokens ato WHERE ato.user_id = u.id) AS api_token_count,
55
-
(SELECT COUNT(*) FROM password_resets pre WHERE pre.user_id = u.id) AS password_reset_count,
56
-
(SELECT COUNT(*) FROM shocker_shares ssh WHERE ssh.shared_with = u.id) AS shocker_share_count,
57
-
(SELECT COUNT(*) FROM shocker_shares_links ssl WHERE ssl.owner_id = u.id) AS shocker_share_link_count,
58
-
(SELECT COUNT(*) FROM users_email_changes uec WHERE uec.user_id = u.id) AS email_change_request_count,
59
-
(SELECT COUNT(*) FROM users_name_changes unc WHERE unc.user_id = u.id) AS name_change_request_count,
60
-
(SELECT COUNT(*) FROM users_activation uac WHERE uac.user_id = u.id) AS user_activation_count,
61
-
(SELECT COUNT(*) FROM devices dev WHERE dev.owner = u.id) AS device_count,
62
-
(SELECT COUNT(*) FROM devices dev JOIN shockers sck ON dev.id = sck.device WHERE dev.owner = u.id) AS shocker_count,
63
-
(SELECT COUNT(*) FROM devices dev JOIN shockers sck ON dev.id = sck.device JOIN shocker_control_logs scl ON scl.shocker_id = sck.id WHERE dev.owner = u.id) AS shocker_control_log_count
64
-
FROM
65
-
users u;
66
68
"""
67
69
);
70
+
71
+
// Recreate the admin_users_view to reflect the new roles structure
-- Drop the view temporarily to modify the underlying table
76
-
DROP VIEW admin_users_view;
77
-
78
83
-- Add the rank column back as a temporary nullable text column
79
84
ALTER TABLE users ADD rank text;
80
85
@@ -100,31 +105,11 @@ UPDATE users
100
105
-- Change the rank column back to a non-nullable rank_type enum
101
106
ALTER TABLE users ALTER COLUMN rank TYPE rank_type USING CAST(rank as rank_type);
102
107
ALTER TABLE users ALTER COLUMN rank SET NOT NULL;
103
-
104
-
-- Recreate the admin_users_view to restore the original structure
105
-
CREATE VIEW admin_users_view AS
106
-
SELECT
107
-
u.id,
108
-
u.name,
109
-
u.email,
110
-
SPLIT_PART(u.password_hash, ':', 1) AS password_hash_type,
111
-
u.created_at,
112
-
u.email_activated,
113
-
u.rank,
114
-
(SELECT COUNT(*) FROM api_tokens ato WHERE ato.user_id = u.id) AS api_token_count,
115
-
(SELECT COUNT(*) FROM password_resets pre WHERE pre.user_id = u.id) AS password_reset_count,
116
-
(SELECT COUNT(*) FROM shocker_shares ssh WHERE ssh.shared_with = u.id) AS shocker_share_count,
117
-
(SELECT COUNT(*) FROM shocker_shares_links ssl WHERE ssl.owner_id = u.id) AS shocker_share_link_count,
118
-
(SELECT COUNT(*) FROM users_email_changes uec WHERE uec.user_id = u.id) AS email_change_request_count,
119
-
(SELECT COUNT(*) FROM users_name_changes unc WHERE unc.user_id = u.id) AS name_change_request_count,
120
-
(SELECT COUNT(*) FROM users_activation uac WHERE uac.user_id = u.id) AS user_activation_count,
121
-
(SELECT COUNT(*) FROM devices dev WHERE dev.owner = u.id) AS device_count,
122
-
(SELECT COUNT(*) FROM devices dev JOIN shockers sck ON dev.id = sck.device WHERE dev.owner = u.id) AS shocker_count,
123
-
(SELECT COUNT(*) FROM devices dev JOIN shockers sck ON dev.id = sck.device JOIN shocker_control_logs scl ON scl.shocker_id = sck.id WHERE dev.owner = u.id) AS shocker_control_log_count
124
-
FROM
125
-
users u;
126
108
"""
127
109
);
110
+
111
+
// Recreate the admin_users_view to restore the original structure
0 commit comments