From 6b2479a7e709fb9670e3f97e8699da737c6197d7 Mon Sep 17 00:00:00 2001 From: ulferts Date: Tue, 9 Nov 2021 15:03:27 +0100 Subject: [PATCH] remove db constraint on journals for reordering During the reordering, duplicates might happen. This depends on the order of execution chosen by the DBMS. As the duplicate is then given a new version having a temporary duplicate is acceptable. --- .../db/migrate/20210726065912_rename_cost_object_type.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/costs/db/migrate/20210726065912_rename_cost_object_type.rb b/modules/costs/db/migrate/20210726065912_rename_cost_object_type.rb index 011a5e1192..2b2cdb7258 100644 --- a/modules/costs/db/migrate/20210726065912_rename_cost_object_type.rb +++ b/modules/costs/db/migrate/20210726065912_rename_cost_object_type.rb @@ -1,5 +1,9 @@ class RenameCostObjectType < ActiveRecord::Migration[6.1] def up + # Remove the index to allow duplicates for the time of the reordering. + # It is recreated right afterwards. + remove_index :journals, %i[journable_type journable_id version] + execute <<~SQL.squish UPDATE journals @@ -19,6 +23,8 @@ class RenameCostObjectType < ActiveRecord::Migration[6.1] journals.journable_type = 'Budget' SQL + add_index :journals, %i[journable_type journable_id version], unique: true + Journal .where(journable_type: 'CostObject') .update_all(journable_type: 'Budget')