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.id
column so it will start with1000
. This will simplify writing specs usingOrganization
model. TheOrganization
factory has been extended with adefault
trait so we can create this default organization if needed. - Do not allow removing the default organization: this done using a
before_destroy
hook. This obviously won't guard against ActiveRecorddelete
method since that is bypassing ActiveRecord hook. Alternatively, we could implement a database trigger that would prevent removing the record withid=1
. - Name: the
Organization
model now has aname
attribute. It is a text column with a limit of 255.names
need 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_default
scope so we can exclude thisOrganization
from 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).destroy
should fail -
Organization.find(1000).destroy
should 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