Add default organization
What does this MR do and why?
Everything in a GitLab installation will belong to an Organization.
Since organization is a new concept, we currently don't have anything linked to it. This MR will add a default organization that can be used to link all existing data to the Organization entity.
Related issue #409628 (closed)
Implementation
- Hard code id
1: I modified the sequence fororganization.idcolumn so it will start with1000. This will simplify writing specs usingOrganizationmodel. TheOrganizationfactory has been extended with adefaulttrait so we can create this default organization if needed. - Do not allow removing the default organization: this done using a
before_destroyhook. This obviously won't guard against ActiveRecorddeletemethod since that is bypassing ActiveRecord hook. Alternatively, we could implement a database trigger that would prevent removing the record withid=1. - Name: the
Organizationmodel now has anameattribute. It is a text column with a limit of 255.namesneed to be unique. I am not sure if we should have unique names, maybe we should only enforce uniqueness for the url part of an organization. (gitlab.com/my_org/) - Default name: 'Unspecified'. Open to alternatives: 'Unassigned', '' (Empty string)... not sure
- Scope: I added a
without_defaultscope so we can exclude thisOrganizationfrom showing up. We could use a default scope but that can be a source of bugs
How to set up and validate locally
- Run the migrations
rake db:migrate - In a Rails console, check
Organization.all: it should return the default organization with id = 1 -
Organization.create(name: 'Test Org')results in a new organization with id = 1000 -
Organization.create(name: 'Test Org')(second time) results in an error (duplicate name) -
Organization.find(1).destroyshould fail -
Organization.find(1000).destroyshould work
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 Rutger Wessels