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

[#53799] Overview page crashes if there have been project custom fields before

Dombi Attila6de73dbab752
diff --git a/db/migrate/20231123111357_create_custom_field_sections.rb b/db/migrate/20231123111357_create_custom_field_sections.rb
index 5d2d259cc1e..49cab93c01e 100644
--- a/db/migrate/20231123111357_create_custom_field_sections.rb
+++ b/db/migrate/20231123111357_create_custom_field_sections.rb
@@ -28,9 +28,19 @@ class CreateCustomFieldSections < ActiveRecord::Migration[7.0]
name: "Project attributes"
)
- # trigger acts_as_list callbacks via updating each record instead of bulk update
- ProjectCustomField.find_each do |project_custom_field|
- project_custom_field.update!(custom_field_section_id: section.id)
- end
+ ActiveRecord::Base.connection.execute <<~SQL.squish
+ UPDATE "custom_fields"
+ SET
+ "position_in_custom_field_section" = "mapping"."new_position",
+ "custom_field_section_id" = #{section.id}
+ FROM (
+ SELECT
+ id,
+ ROW_NUMBER() OVER (ORDER BY updated_at) AS new_position
+ FROM "custom_fields"
+ WHERE "custom_fields"."type" = 'ProjectCustomField'
+ ) AS "mapping"
+ WHERE "custom_fields"."id" = "mapping"."id";
+ SQL
end
end