Backport of 'Backfill NULL organization_id on oauth_applications'

What does this MR do and why?

Backports a post-deploy migration to 18-11-stable-ee that backfills NULL organization_id values on oauth_applications to 1 (the default organization).

This is needed because the 19.0 post-deploy migration 20260417155126_add_not_null_constraint_to_oauth_applications_organization_id fails with PG::CheckViolation on Dedicated and self-managed instances where the GitLab Pages (and Mattermost) OAuth application was created via gitlab-ctl reconfigure or CNG's custom-instance-setup script without an organization_id. The backfill must run during 18.11 post-deploy, before the instance upgrades to 19.0 and the constraint validation runs.

Database query plan

The migration runs a single UPDATE with a WHERE organization_id IS NULL predicate. On gitlab.com and any instance where the prior batched background migration ran successfully, this matches zero rows and is effectively a no-op. On affected Dedicated/self-managed instances, only a handful of rows are affected.

EXPLAIN UPDATE oauth_applications SET organization_id = 1 WHERE organization_id IS NULL;
 ModifyTable on public.oauth_applications  (cost=0.43..1.95 rows=0 width=0) (actual time=0.710..0.711 rows=0 loops=1)
   Buffers: shared read=3
   ->  Index Scan using idx_oauth_applications_organization_id on public.oauth_applications  (cost=0.43..1.95 rows=1 width=14) (actual time=0.707..0.708 rows=0 loops=1)
         Index Cond: (oauth_applications.organization_id IS NULL)
         Buffers: shared read=3
Settings: seq_page_cost = '4', effective_cache_size = '472585MB', jit = 'off', random_page_cost = '1.5', work_mem = '230MB'

https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/53189/commands/155085

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • This MR is backporting a bug fix, documentation update, or spec fix, previously merged in the default branch.
  • The MR that fixed the bug on the default branch has been deployed to GitLab.com (not applicable for documentation or spec changes).
  • The MR title is descriptive (e.g. "Backport of 'title of default branch MR'"). This is important, since the title will be copied to the patch blog post.
  • Required labels have been applied to this merge request
  • This MR has been approved by a maintainer (only one approval is required).
  • Ensure the e2e:test-on-omnibus-ee job has succeeded, or if it has failed, investigate the failures. If you determine the failures are unrelated, you may proceed. If you need assistance investigating, request help in the #s_developer_experience Slack channel to confirm the failures are unrelated to the merge request.

Note to the merge request author and maintainer

If you have questions about the patch release process, please:

Edited by Shilpa Kundapur

Merge request reports

Loading