Skip to content

Draft: Ensure Default Organization exists on self-managed instances

Rutger Wessels requested to merge 414930-ensure-default-organization-exists into master

What does this MR do and why?

In omnibus-gitlab#8484 (closed), some self-managed customers reported that the default organization is missing from their installation. Initially, we anticipated that should not happen (we seed default organization for new installations and have database migrations for existing installations). This MR will make sure that default organization exists

Implementation is using a Sidekiq worker during application start. I also considered using Organizations::Organization.default_organization method but we have no guarantee that that method is called soon enough.

Related to #414930 (closed)

Implementation

  • After Rails Application start, we schedule a Sidekiq Worker, only if Gitlab.com? is false
  • The worker will create the Default Organization if it does not exist

We rely on worker deduplication. The worker will be fast: if the organization exists, it will perform only one SELECT query against organizations table primary key.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

Warning: This will delete data from your PostgreSQL instance!

Using gdk psql, delete the trigger and delete organizations. It will cascade.

DROP TRIGGER prevent_delete_of_default_organization_before_destroy ON public.organizations;
DELETE FROM organizations WHERE id = 1;

Exit psql and run gdk restart.

Verify that the default organization is back by using gdk psql:

SELECT * FROM organizations WHERE id = 1;

# Create trigger
create trigger prevent_delete_of_default_organization_before_destroy before
delete
    on
    public.organizations for each row execute function prevent_delete_of_default_organization();
Edited by Rutger Wessels

Merge request reports