Skip to content

Validate uniqnuess of member role name

Jarka Košanová requested to merge 438472-validate-cr-name-uniqness into master

What does this MR do and why?

It adds a requirement that a name is unique per namespace:

  • it adds a validation to the model
  • it removes existing duplicates by changing the name of duplicates
  • it adds unique index to the member_roles table

Database queries

  • duplicates removal
  • we have around 10 member role records on Gitlab.com and we expect maximum of hundreds of records on self-managed instances (more likely tons)

MR acceptance checklist

Screenshots or screen recordings

How to set up and validate locally

  1. Before checking out this branch, create few duplicates member roles (duplicated = same name and namespace), eg. in console:
mr1 = MemberRole.create(name: 'member role', base_access_level: 10, read_code: true)
mr2 = MemberRole.create(name: 'member role', base_access_level: 10, read_code: true)
mr3 = MemberRole.create(name: 'member role', base_access_level: 10, read_code: true)
  1. Check out this branch
  2. Run the migration
  3. Check if the duplicated names were updated, eg. by checking in the console: MemberRole.all.map(&:name)
  4. Try to create the duplicated records again, this should not work

Related to #438472 (closed)

Edited by Jarka Košanová

Merge request reports

Loading