Commit 26d13a5b authored by Andreas Brandl's avatar Andreas Brandl

Cleanup internal id records for epics.

parent 555ad5b4
...@@ -20,6 +20,7 @@ class DeleteInconsistentInternalIdRecords < ActiveRecord::Migration ...@@ -20,6 +20,7 @@ class DeleteInconsistentInternalIdRecords < ActiveRecord::Migration
delete_internal_id_records('milestones', 'project_id') delete_internal_id_records('milestones', 'project_id')
delete_internal_id_records('milestones', 'namespace_id', 'group_id') delete_internal_id_records('milestones', 'namespace_id', 'group_id')
delete_internal_id_records('ci_pipelines', 'project_id') delete_internal_id_records('ci_pipelines', 'project_id')
delete_internal_id_records('epics', 'namespace_id', 'group_id')
end end
end end
......
...@@ -79,7 +79,7 @@ describe DeleteInconsistentInternalIdRecords, :migration do ...@@ -79,7 +79,7 @@ describe DeleteInconsistentInternalIdRecords, :migration do
end end
context 'for milestones (by group)' do context 'for milestones (by group)' do
# milestones (by group) is a little different than all of the other models # milestones (by group) is a little different than most of the other models
let!(:group1) { create(:group) } let!(:group1) { create(:group) }
let!(:group2) { create(:group) } let!(:group2) { create(:group) }
let!(:group3) { create(:group) } let!(:group3) { create(:group) }
...@@ -116,4 +116,43 @@ describe DeleteInconsistentInternalIdRecords, :migration do ...@@ -116,4 +116,43 @@ describe DeleteInconsistentInternalIdRecords, :migration do
expect { migrate! }.not_to change { internal_id_query.call(group3).size } expect { migrate! }.not_to change { internal_id_query.call(group3).size }
end end
end end
context 'for milestones (by group)' do
# epics (by group) is a little different than most of the other models
let!(:group1) { create(:group) }
let!(:group2) { create(:group) }
let!(:group3) { create(:group) }
let(:internal_id_query) { ->(group) { InternalId.where(usage: InternalId.usages['epics'], namespace: group) } }
before do
create_list(:epic, 3, group: group1)
create_list(:epic, 3, group: group2)
create_list(:epic, 3, group: group3)
internal_id_query.call(group1).first.tap do |iid|
iid.last_value = iid.last_value - 2
# This is an inconsistent record
iid.save!
end
internal_id_query.call(group3).first.tap do |iid|
iid.last_value = iid.last_value + 2
# This is a consistent record
iid.save!
end
end
it "deletes inconsistent records" do
expect { migrate! }.to change { internal_id_query.call(group1).size }.from(1).to(0)
end
it "retains consistent records" do
expect { migrate! }.not_to change { internal_id_query.call(group2).size }
end
it "retains consistent records, especially those with a greater last_value" do
expect { migrate! }.not_to change { internal_id_query.call(group3).size }
end
end
end end
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