-
Notifications
You must be signed in to change notification settings - Fork 888
chore: Rename 'admin' to 'owner' #3498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
233962c
Add migration for removing the 'admin' role
Emyrk 5ca12ce
Rename admin role -> owner
Emyrk 52cac69
Update migration to promote either admin
Emyrk fb4f80f
fixup! Update migration to promote either admin
Emyrk 81c2ee0
Merge remote-tracking branch 'origin/main' into stevenmasley/2135/rol…
Emyrk 21e48e7
Update "admin" -> "owner" in docs
Emyrk 9c122a6
Fix unit test for role rename
Emyrk dd9e323
Fix spacing on SQL queries
Emyrk 4a4845a
Import order
Emyrk ec56c60
Fix typo
Emyrk a5598fa
Update coderd/database/migrations/000034_remove_admin_role.down.sql
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
coderd/database/migrations/000034_remove_admin_role.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 20 additions & 0 deletions
20
coderd/database/migrations/000034_remove_admin_role.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
coadler marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could technically cause the query to fail if no rows are found, I think doing
id IN (...)
would allow it to match no rows.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting. Let me try it out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coadler It does not seem to matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I thought this would've caused an issue when you compared a non-null field to null. Sounds good then!