Skip to content

Backfill default_branch_protection_defaults for namespace settings

What does this MR do and why?

Backfill default_branch_protection_defaults for namespace settings

This commit backfills default_branch_protection_defaults for namespace settings table

Changelog: other

gitlabhq_dblab=# select count(*) from namespaces;
  count
----------
 49877449

Migration Logs

❯ rails db:migrate
main: == [advisory_lock_connection] object_id: 224220, pg_backend_pid: 82897
main: == 20230724071541 QueueBackfillDefaultBranchProtectionNamespaceSetting: migrating
main: == 20230724071541 QueueBackfillDefaultBranchProtectionNamespaceSetting: migrated (0.0774s)

main: == [advisory_lock_connection] object_id: 224220, pg_backend_pid: 82897
ci: == [advisory_lock_connection] object_id: 224580, pg_backend_pid: 82899
ci: == 20230724071541 QueueBackfillDefaultBranchProtectionNamespaceSetting: migrating
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_internal, :gitlab_shared].
ci: == 20230724071541 QueueBackfillDefaultBranchProtectionNamespaceSetting: migrated (0.0106s)

ci: == [advisory_lock_connection] object_id: 224580, pg_backend_pid: 82899

❯ rake db:rollback:main STEP=1
main: == [advisory_lock_connection] object_id: 240880, pg_backend_pid: 87760
main: == 20230724071541 QueueBackfillDefaultBranchProtectionNamespaceSetting: reverting
main: == 20230724071541 QueueBackfillDefaultBranchProtectionNamespaceSetting: reverted (0.0869s)

main: == [advisory_lock_connection] object_id: 240880, pg_backend_pid: 87760

Queries

read query

explain SELECT namespace_settings.* FROM namespace_settings WHERE namespace_settings.namespace_id IN (9970, 9971, 9972, 9973)

execution plan

 Index Scan using namespace_settings_pkey on public.namespace_settings  (cost=0.56..13.85 rows=4 width=114) (actual time=8.176..13.433 rows=4 loops=1)  
   Index Cond: (namespace_settings.namespace_id = ANY ('{9970,9971,9972,9973}'::integer[]))  
   Buffers: shared hit=15 read=8  
   I/O Timings: read=13.235 write=0.000  

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/20657/commands/67798

write query

explain UPDATE namespace_settings SET default_branch_protection_defaults = '{ "allowed_to_push": [ { "access_level": 30 } ], "allow_force_push": true, "allowed_to_merge": [ { "access_level": 30 } ] }' WHERE namespace_id = 9970;

execution plan

ModifyTable on public.namespace_settings  (cost=0.56..3.58 rows=1 width=153) (actual time=6.106..6.107 rows=0 loops=1)
   Buffers: shared hit=22 read=8 dirtied=2
   I/O Timings: read=5.322 write=0.000
   ->  Index Scan using namespace_settings_pkey on public.namespace_settings  (cost=0.56..3.58 rows=1 width=153) (actual time=0.055..0.060 rows=1 loops=1)
         Index Cond: (namespace_settings.namespace_id = 9970)
         Buffers: shared hit=5
         I/O Timings: read=0.000 write=0.000

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/20657/commands/67801

How to set up and validate locally

  1. Check NamespaceSetting.where.not(default_branch_protection_defaults: {}).count is zero.
  2. Run bundle exec rails db:migrate
  3. Go to https://gdk.test:3000/admin/background_migrations?tab=finished and check job is finished
  4. Check data is correctly inserted in column default_branch_protection_defaults of table namespace_settings

MR acceptance checklist

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

Related to #408153 (closed)

Edited by Harsimar Sandhu

Merge request reports