diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 18:42:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 18:42:17 +0300 |
commit | 44fdf983bd35328dd577d3d3650d14163ef3e2b6 (patch) | |
tree | 84ff300d056cfbabb5a0fe2a9cbaa80aaeab1cc5 /lib/gitlab/background_migration | |
parent | bc9fa07b26184b5c94808f704db6ea1ac81bf4de (diff) |
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r-- | lib/gitlab/background_migration/backfill_push_rules_id_in_projects.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/backfill_push_rules_id_in_projects.rb b/lib/gitlab/background_migration/backfill_push_rules_id_in_projects.rb new file mode 100644 index 00000000000..9b9ef70424a --- /dev/null +++ b/lib/gitlab/background_migration/backfill_push_rules_id_in_projects.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Class that will insert record into project_push_rules + # for each existing push_rule + class BackfillPushRulesIdInProjects + # Temporary AR table for push rules + class ProjectSetting < ActiveRecord::Base + self.table_name = 'project_settings' + end + + def perform(start_id, stop_id) + ProjectSetting.connection.execute(<<~SQL) + UPDATE project_settings ps1 + SET push_rule_id = pr.id + FROM project_settings ps2 + INNER JOIN push_rules pr + ON ps2.project_id = pr.project_id + WHERE pr.is_sample = false + AND pr.id BETWEEN #{start_id} AND #{stop_id} + AND ps1.project_id = ps2.project_id + SQL + end + end + end +end |