Commit d8799f5c authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch '214983-schedulebackfillpushrulesidinprojects-fails-if-there-are-multiple-rows-in' into 'master'

Fix ScheduleBackfillPushRulesIdInProjects fails if there are multiple rows in application_settings

Closes #214983

See merge request gitlab-org/gitlab!29922
parents 0f1669a9 1df5653a
......@@ -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
......
......@@ -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!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment