Skip to content

Set project organization from its namespace

Abdul Wadood requested to merge 443857-derive-child-org-from-parent into master

What does this MR do and why?

This is the first installment to make sure every project is instantiated with an organization. Here we have introduced a before_validation that sets the project's organization_id to the project's parent's organization_id.

The next steps are:

  1. Remove default 1 for the projects.organization_id column.
  2. Check the organization_id column if it's being set to null through some code path.
  3. Fix the above code path and do a backfill.
  4. If no nulls are found then add a validation and a null check constraint for Project#organization.

The above is in accordance with our database guidelines to set a NOT NULL constraint for a column.

Also see !148654 (comment 1864610717).

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

  1. In rails console enable the experiment fully
    Feature.enable(:ui_for_organizations)
    Feature.enable(:allow_organization_creation)
  2. Drop the default in gdk psql by running ALTER TABLE projects ALTER COLUMN organization_id DROP DEFAULT;
  3. Visit the organizations list page https://gdk.test:3000/-/organizations and create a new organization and a new group under that organization.
  4. On the master branch, create a new project under the above group and check the project's organization_id. Project.last.organization_id will be nil.
  5. On this branch, create a new project under the above group and check the project's organization_id. Project.last.organization_id will be equal to the above organization's ID.
  6. Restore the default: ALTER TABLE projects ALTER COLUMN organization_id SET DEFAULT 1;

Related to #443857 (closed)

Edited by Abdul Wadood

Merge request reports