Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-11-07 06:10:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-11-07 06:10:53 +0300
commit2ce8e7fcf32b18db57a5547fda35044e55cdc1eb (patch)
tree64bbbdd27d96d158ac1642d496aeaa199dd16dd1 /lib/gitlab
parent611897b987d439b0d736eb87415b8ca32bdaa282 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/background_migration/backfill_packages_tags_project_id.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/backfill_packages_tags_project_id.rb b/lib/gitlab/background_migration/backfill_packages_tags_project_id.rb
new file mode 100644
index 00000000000..04fd09f81f0
--- /dev/null
+++ b/lib/gitlab/background_migration/backfill_packages_tags_project_id.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # This migration populates the new `packages_tags.project_id` column from joining with `packages_packages` table
+ class BackfillPackagesTagsProjectId < BatchedMigrationJob
+ operation_name :update_all # This is used as the key on collecting metrics
+ scope_to ->(relation) { relation.where(project_id: nil) }
+ feature_category :package_registry
+
+ def perform
+ each_sub_batch do |sub_batch|
+ joined = sub_batch
+ .joins('INNER JOIN packages_packages ON packages_tags.package_id = packages_packages.id')
+ .select('packages_tags.id, packages_packages.project_id')
+
+ ApplicationRecord.connection.execute <<~SQL
+ WITH joined_cte(packages_tag_id, project_id) AS MATERIALIZED (
+ #{joined.to_sql}
+ )
+ UPDATE packages_tags
+ SET project_id = joined_cte.project_id
+ FROM joined_cte
+ WHERE id = joined_cte.packages_tag_id
+ SQL
+ end
+ end
+ end
+ end
+end