Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52cac69

Browse files
committed
Update migration to promote either admin
1 parent 5ca12ce commit 52cac69

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

coderd/database/migrations/000034_remove_admin_role.down.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ UPDATE
33
SET
44
-- Replace 'template-admin' and 'user-admin' role with 'admin'
55
rbac_roles = array_append(
6-
array_remove(
7-
array_remove(users.rbac_roles, 'template-admin'),
8-
'user-admin'
9-
), 'admin')
6+
array_remove(
7+
array_remove(rbac_roles, 'template-admin'),
8+
'user-admin'
9+
), 'admin')
1010
WHERE
11-
-- Only on existing admins
12-
ARRAY ['template-admin', 'user-admin'] <@ rbac_roles;
11+
-- Only on existing admins. If they have either role, make them an admin
12+
ARRAY ['template-admin', 'user-admin'] && rbac_roles;
1313

1414

1515
UPDATE

coderd/database/migrations/000034_remove_admin_role.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SET
44
-- Replace the role 'admin' with the role 'owner'
55
rbac_roles = array_replace(rbac_roles, 'admin', 'owner')
66
WHERE
7-
-- Update the first user with the role 'admin'. This should be the first
7+
-- Update the first user with the role 'admin'. This should be the first
88
-- user ever, but if that user was demoted from an admin, then choose
99
-- the next best user.
1010
id = (SELECT id FROM users WHERE 'admin' = ANY(rbac_roles) ORDER BY created_at ASC LIMIT 1);

0 commit comments

Comments
 (0)