diff options
-rw-r--r-- | db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb | 5 | ||||
-rw-r--r-- | spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb | 14 |
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! |