Add organization_id to admin_roles table
What does this MR do and why?
This change is necessary to prepare the admin_roles table for protocells.
The main changes include:
- Adding an "organization_id" field to admin roles that links each role to an organization (defaulting to organization #1 (closed) for existing roles)
- Updating the uniqueness rule so that role names only need to be unique within each organization, rather than globally unique
- Creating a database relationship between admin roles and organizations with proper constraints
- Updating the database index to support the new organization scoped uniqueness requirement
- Modifying tests and factories to work with the new organization requirement
This allows different organizations to have their own separate admin roles with potentially the same names, providing better isolation and flexibility in multi-organization environments.
References
Screenshots or screen recordings
Before:
SELECT 1 AS one
FROM "admin_roles"
WHERE "admin_roles"."name" = 'root'
LIMIT 1
Time: 0.417 ms
- planning: 0.369 ms
- execution: 0.048 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 0 from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/43738/commands/133619
After:
ALTER TABLE admin_roles ADD COLUMN organization_id bigint DEFAULT 1 NOT NULL;
CREATE UNIQUE INDEX index_admin_roles_on_organization_id_and_name ON admin_roles USING btree (organization_id, name);
DROP INDEX IF EXISTS index_admin_roles_on_name;
ALTER TABLE ONLY admin_roles ADD CONSTRAINT fk_74591b3a95 FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE;
SELECT 1 AS one
FROM "admin_roles"
WHERE "admin_roles"."name" = 'root'
AND "admin_roles"."organization_id" = 1
LIMIT 1
Time: 0.611 ms
- planning: 0.561 ms
- execution: 0.050 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 0 from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/43738/commands/133625
How to set up and validate locally
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by mo khan