Validate uniqnuess of member role name
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
- 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)
- Check out this branch
- Run the migration
- Check if the duplicated names were updated, eg. by checking in the console:
MemberRole.all.map(&:name)
- Try to create the duplicated records again, this should not work
Related to #438472 (closed)
Edited by Jarka Košanová