diff options
Diffstat (limited to 'db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb')
-rw-r--r-- | db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb b/db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb new file mode 100644 index 00000000000..0b65db7aab4 --- /dev/null +++ b/db/post_migrate/20211209103048_backfill_project_namespaces_for_group.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class BackfillProjectNamespacesForGroup < Gitlab::Database::Migration[1.0] + MIGRATION = 'ProjectNamespaces::BackfillProjectNamespaces' + DELAY_INTERVAL = 2.minutes + GROUP_ID = 9970 # picking gitlab-org group. + + disable_ddl_transaction! + + def up + return unless Gitlab.com? || Gitlab.staging? + + projects_table = ::Gitlab::BackgroundMigration::ProjectNamespaces::Models::Project.arel_table + hierarchy_cte_sql = Arel.sql(::Gitlab::BackgroundMigration::ProjectNamespaces::BackfillProjectNamespaces.hierarchy_cte(GROUP_ID)) + group_projects = ::Gitlab::BackgroundMigration::ProjectNamespaces::Models::Project.where(projects_table[:namespace_id].in(hierarchy_cte_sql)) + + min_id = group_projects.minimum(:id) + max_id = group_projects.maximum(:id) + + return if min_id.blank? || max_id.blank? + + queue_batched_background_migration( + MIGRATION, + :projects, + :id, + GROUP_ID, + 'up', + job_interval: DELAY_INTERVAL, + batch_min_value: min_id, + batch_max_value: max_id, + sub_batch_size: 25, + batch_class_name: 'BackfillProjectNamespacePerGroupBatchingStrategy' + ) + end + + def down + return unless Gitlab.com? || Gitlab.staging? + + Gitlab::Database::BackgroundMigration::BatchedMigration + .for_configuration(MIGRATION, :projects, :id, [GROUP_ID, 'up']).delete_all + end +end |