mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: Rename 'admin' to 'owner' (#3498)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
This commit is contained in:
22
coderd/database/migrations/000034_remove_admin_role.down.sql
Normal file
22
coderd/database/migrations/000034_remove_admin_role.down.sql
Normal file
@ -0,0 +1,22 @@
|
||||
UPDATE
|
||||
users
|
||||
SET
|
||||
-- Replace 'template-admin' and 'user-admin' role with 'admin'
|
||||
rbac_roles = array_append(
|
||||
array_remove(
|
||||
array_remove(rbac_roles, 'template-admin'),
|
||||
'user-admin'
|
||||
), 'admin')
|
||||
WHERE
|
||||
-- Only on existing admins. If they have either role, make them an admin
|
||||
ARRAY ['template-admin', 'user-admin'] && rbac_roles;
|
||||
|
||||
|
||||
UPDATE
|
||||
users
|
||||
SET
|
||||
-- Replace 'owner' with 'admin'
|
||||
rbac_roles = array_replace(rbac_roles, 'owner', 'admin')
|
||||
WHERE
|
||||
-- Only on the owner
|
||||
'owner' = ANY(rbac_roles);
|
20
coderd/database/migrations/000034_remove_admin_role.up.sql
Normal file
20
coderd/database/migrations/000034_remove_admin_role.up.sql
Normal file
@ -0,0 +1,20 @@
|
||||
UPDATE
|
||||
users
|
||||
SET
|
||||
-- Replace the role 'admin' with the role 'owner'
|
||||
rbac_roles = array_replace(rbac_roles, 'admin', 'owner')
|
||||
WHERE
|
||||
-- Update the first user with the role 'admin'. This should be the first
|
||||
-- user ever, but if that user was demoted from an admin, then choose
|
||||
-- the next best user.
|
||||
id = (SELECT id FROM users WHERE 'admin' = ANY(rbac_roles) ORDER BY created_at ASC LIMIT 1);
|
||||
|
||||
|
||||
UPDATE
|
||||
users
|
||||
SET
|
||||
-- Replace 'admin' role with 'template-admin' and 'user-admin'
|
||||
rbac_roles = array_cat(array_remove(rbac_roles, 'admin'), ARRAY ['template-admin', 'user-admin'])
|
||||
WHERE
|
||||
-- Only on existing admins
|
||||
'admin' = ANY(rbac_roles);
|
Reference in New Issue
Block a user