[#4184] Use a mapper to track primary key differences on Deliverables.
This commit is contained in:
@@ -38,6 +38,9 @@ module RedmineContracts
|
||||
def self.migrate(old_data)
|
||||
@@data = YAML.load(old_data)
|
||||
|
||||
# Map old deliverable ids to the new ones
|
||||
@deliverable_mapper = {}
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@@data.each do |old_deliverable|
|
||||
|
||||
@@ -74,8 +77,14 @@ module RedmineContracts
|
||||
append_old_deliverable_to_notes(old_deliverable, deliverable)
|
||||
|
||||
deliverable.save!
|
||||
|
||||
@deliverable_mapper[old_deliverable['id']] = deliverable.id
|
||||
end
|
||||
end
|
||||
|
||||
@deliverable_mapper.each do |old, new|
|
||||
Issue.update_all(["deliverable_id = ?", new], ["deliverable_id = ?", old])
|
||||
end
|
||||
end
|
||||
|
||||
def self.data
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@
|
||||
cost_per_hour: 85.0
|
||||
subject: Version 1.0
|
||||
materials: 0.0
|
||||
id: 3
|
||||
id: 4
|
||||
type: FixedDeliverable
|
||||
project_manager_signoff: true
|
||||
profit:
|
||||
|
||||
@@ -172,6 +172,28 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
context "converting issue ids" do
|
||||
setup do
|
||||
@issue1 = Issue.generate_for_project!(@project_two, :deliverable_id => 2)
|
||||
@issue2 = Issue.generate_for_project!(@project_two, :deliverable_id => 4)
|
||||
|
||||
end
|
||||
|
||||
should "keep the same Deliverable assigned" do
|
||||
RedmineContracts::BudgetPluginMigration.migrate(@data)
|
||||
|
||||
assert_equal "Deliverable 2", @issue1.reload.deliverable.title
|
||||
assert_equal "Version 1.0", @issue2.reload.deliverable.title
|
||||
end
|
||||
|
||||
should "handle primary key differences between the old and new Deliverables" do
|
||||
RedmineContracts::BudgetPluginMigration.migrate(@data)
|
||||
|
||||
# The "third" deliverable has an id of 4
|
||||
assert_equal "Version 1.0", @issue2.reload.deliverable.title
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user