Add name and description fields to member_roles
What does this MR do and why?
- These attributes will be used for labeling these attributes
- Name is required but we are adding a default of "Custom" for existing records
- Description is optional
- I am going to add the documentation in a separate MR to keep this one smaller
- #416751 (closed)
How to set up and validate locally
-
Create a custom role and set name and description (for any Ultimate group):
curl --request POST --header "Content-Type: application/json" --header "Authorization: Bearer $ACCESS_TOKEN" --data '{"base_access_level" : 10, "read_code" : true, "name" : "Special name", "description" : "This is my special role"}' "https://gdk.test:3443/api/v4/groups/flightjs/member_roles" => {"id":8,"group_id":33,"name":"Special name","description":"This is my special role","base_access_level":10,"read_code":true,"read_vulnerability":false,"admin_vulnerability":false}
- Create a custom role without setting name or description (
name
attribute should be set automatically):curl --request POST --header "Content-Type: application/json" --header "Authorization: Bearer $ACCESS_TOKEN" --data '{"base_access_level" : 10, "read_code" : true}' "https://gdk.test:3443/api/v4/groups/flightjs/member_roles" => {"id":9,"group_id":33,"name":"Guest - custom","description":null,"base_access_level":10,"read_code":true,"read_vulnerability":false,"admin_vulnerability":false}
Migration
Migrate
bundle exec rails db:migrate
main: == [advisory_lock_connection] object_id: 223760, pg_backend_pid: 93214
main: == 20230714020854 AddNameAndDescriptionToMemberRoles: migrating ===============
main: -- add_column(:member_roles, :name, :text, {:null=>false, :default=>"Custom"})
main: -> 0.0032s
main: -- add_column(:member_roles, :description, :text)
main: -> 0.0005s
main: -- transaction_open?()
main: -> 0.0000s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("ALTER TABLE member_roles\nADD CONSTRAINT check_9907916995\nCHECK ( char_length(name) <= 255 )\nNOT VALID;\n")
main: -> 0.0015s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0003s
main: -- execute("ALTER TABLE member_roles VALIDATE CONSTRAINT check_9907916995;")
main: -> 0.0008s
main: -- execute("RESET statement_timeout")
main: -> 0.0003s
main: -- transaction_open?()
main: -> 0.0000s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("ALTER TABLE member_roles\nADD CONSTRAINT check_4364846f58\nCHECK ( char_length(description) <= 255 )\nNOT VALID;\n")
main: -> 0.0005s
main: -- execute("ALTER TABLE member_roles VALIDATE CONSTRAINT check_4364846f58;")
main: -> 0.0004s
main: == 20230714020854 AddNameAndDescriptionToMemberRoles: migrated (0.1743s) ======
main: == [advisory_lock_connection] object_id: 223760, pg_backend_pid: 93214
Rollback
bundle exec rails db:rollback:main VERSION=20230714020854
main: == [advisory_lock_connection] object_id: 223480, pg_backend_pid: 92749
main: == 20230714020854 AddNameAndDescriptionToMemberRoles: reverting ===============
main: -- remove_column(:member_roles, :name, :text)
main: -> 0.0046s
main: -- remove_column(:member_roles, :description, :text)
main: -> 0.0005s
main: == 20230714020854 AddNameAndDescriptionToMemberRoles: reverted (0.0085s) ======
main: == [advisory_lock_connection] object_id: 223480, pg_backend_pid: 92749
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Jessie Young