Skip to content

Add default organization

Rutger Wessels requested to merge rw-create-default-organization into master

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 for organization.id column so it will start with 1000. This will simplify writing specs using Organization model. The Organization factory has been extended with a default 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 ActiveRecord delete method since that is bypassing ActiveRecord hook. Alternatively, we could implement a database trigger that would prevent removing the record with id=1.
  • Name: the Organization model now has a name 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 this Organization from showing up. We could use a default scope but that can be a source of bugs

How to set up and validate locally

  1. Run the migrations rake db:migrate
  2. In a Rails console, check Organization.all: it should return the default organization with id = 1
  3. Organization.create(name: 'Test Org') results in a new organization with id = 1000
  4. Organization.create(name: 'Test Org') (second time) results in an error (duplicate name)
  5. Organization.find(1).destroy should fail
  6. 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.

Edited by Rutger Wessels

Merge request reports