Set project organization from its namespace
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:
- Remove default 1 for the
projects.organization_id
column. - Check the organization_id column if it's being set to null through some code path.
- Fix the above code path and do a backfill.
- 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
- In rails console enable the experiment fully
Feature.enable(:ui_for_organizations) Feature.enable(:allow_organization_creation)
- Drop the default in
gdk psql
by runningALTER TABLE projects ALTER COLUMN organization_id DROP DEFAULT;
- Visit the organizations list page https://gdk.test:3000/-/organizations and create a new organization and a new group under that organization.
- On the master branch, create a new project under the above group and check the project's organization_id.
Project.last.organization_id
will benil
. - 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. - Restore the default:
ALTER TABLE projects ALTER COLUMN organization_id SET DEFAULT 1;
Related to #443857 (closed)
Edited by Abdul Wadood