summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 22:10:04 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 22:10:04 +0000
commit8bdbf220176b3c4df35dbf01da3dc8b2d507f351 (patch)
treeaaabfc8906f31a1f62d1b5adbcf65dad5cd13aa0
parent81bf49d9ea87a9dae5f0fd46a2bde8243459a7b1 (diff)
downloadgitlab-ce-8bdbf220176b3c4df35dbf01da3dc8b2d507f351.tar.gz
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
-rw-r--r--db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb5
-rw-r--r--spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb14
2 files changed, 18 insertions, 1 deletions
diff --git a/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb b/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb
index b25b3365e12..8ff3ab6aa0c 100644
--- a/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb
+++ b/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb
@@ -18,7 +18,10 @@ class ScheduleBackfillPushRulesIdInProjects < ActiveRecord::Migration[6.0]
# Update one record that is connected to the instance
value_to_be_updated_to = ScheduleBackfillPushRulesIdInProjects::PushRules.find_by(is_sample: true)&.id
- execute "UPDATE application_settings SET push_rule_id = #{value_to_be_updated_to}" if value_to_be_updated_to
+ if value_to_be_updated_to
+ execute "UPDATE application_settings SET push_rule_id = #{value_to_be_updated_to}
+ WHERE id IN (SELECT MAX(id) FROM application_settings);"
+ end
ApplicationSetting.expire
diff --git a/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb b/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb
index 77648f5c64a..77721eab77d 100644
--- a/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb
+++ b/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb
@@ -20,6 +20,20 @@ describe ScheduleBackfillPushRulesIdInProjects do
expect(setting.push_rule_id).to eq(sample_rule.id)
end
+ it 'adds global rule association to last application settings when there is more than one record without failing' do
+ application_settings = table(:application_settings)
+ setting_old = application_settings.create!
+ setting = application_settings.create!
+ sample_rule = push_rules.create!(is_sample: true)
+
+ Sidekiq::Testing.fake! do
+ disable_migrations_output { migrate! }
+ end
+
+ expect(setting_old.reload.push_rule_id).to be_nil
+ expect(setting.reload.push_rule_id).to eq(sample_rule.id)
+ end
+
it 'schedules worker to migrate project push rules' do
rule_1 = push_rules.create!
rule_2 = push_rules.create!