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-02-06 12:12:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-06 12:12:20 +0300
commita6d9ec9567a4f0b6401295e6744ab394fa3b0033 (patch)
treef864b1123ce9ffe85cfebcd55650c8a867c6eb36 /lib/gitlab/background_migration
parentcfe9f9a5b3a338744b3caf1bf55f8fd290618d0e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects.rb b/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects.rb
new file mode 100644
index 00000000000..592ef3220ff
--- /dev/null
+++ b/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # A job to nullify `projects.creator_id` column of projects who creator
+ # does not exist in `users` table anymore.
+ class NullifyCreatorIdColumnOfOrphanedProjects < BatchedMigrationJob
+ scope_to ->(relation) do
+ relation.where.not(creator_id: nil)
+ .joins('LEFT OUTER JOIN users ON users.id = projects.creator_id')
+ .where(users: { id: nil })
+ end
+
+ operation_name :update_all
+ feature_category :projects
+
+ def perform
+ each_sub_batch do |sub_batch|
+ sub_batch.update_all(creator_id: nil)
+ end
+ end
+ end
+ end
+end