Add foreign key to organization_users.organization_id column

What does this MR do and why?

organization_users table links users to organizations. Originally, this was implemented using loose foreign key. But since both organization_users and organizations are now part of gitlab_main_cell, we can use database foreign keys.

In a previous MR, this already happened for user_id, this MR will also make organization_id a foreign key.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

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.

Migration output

Up:
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE organization_users ADD CONSTRAINT fk_8471abad75 FOREIGN KEY (organization_id) REFERENCES organizations (id) ON DELETE CASCADE NOT VALID;")
main:    -> 0.0015s
Down:
main: -- transaction_open?(nil)
main:    -> 0.0098s
main: -- remove_foreign_key(:organization_users, {:column=>:organization_id})
main:    -> 0.0027s

Related to #493506 (closed)

Merge request reports

Loading