Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

remove db constraint on journals for reordering

ulferts6b2479a7e709
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 011a5e11923..2b2cdb72580 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')