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

Build index concurrently after adding data

Klaus Zandersc0b2aafdf715
diff --git a/modules/costs/db/migrate/20250416095154_add_entity_to_time_entry.rb b/modules/costs/db/migrate/20250416095154_add_entity_to_time_entry.rb
index a6a0c4e2c9d..7c9a2e83110 100644
--- a/modules/costs/db/migrate/20250416095154_add_entity_to_time_entry.rb
+++ b/modules/costs/db/migrate/20250416095154_add_entity_to_time_entry.rb
@@ -2,8 +2,8 @@
class AddEntityToTimeEntry < ActiveRecord::Migration[8.0]
def up
- add_reference :time_entries, :entity, polymorphic: true, index: true
- add_reference :time_entry_journals, :entity, polymorphic: true, index: true
+ add_reference :time_entries, :entity, polymorphic: true
+ add_reference :time_entry_journals, :entity, polymorphic: true
execute <<~SQL.squish
UPDATE time_entries
diff --git a/modules/costs/db/migrate/20250416112143_add_entity_to_cost_entry.rb b/modules/costs/db/migrate/20250416112143_add_entity_to_cost_entry.rb
index 2be947243a0..2dc8ed88555 100644
--- a/modules/costs/db/migrate/20250416112143_add_entity_to_cost_entry.rb
+++ b/modules/costs/db/migrate/20250416112143_add_entity_to_cost_entry.rb
@@ -2,7 +2,7 @@
class AddEntityToCostEntry < ActiveRecord::Migration[8.0]
def up
- add_reference :cost_entries, :entity, polymorphic: true, index: true
+ add_reference :cost_entries, :entity, polymorphic: true
change_column_null :cost_entries, :work_package_id, true
execute <<~SQL.squish
diff --git a/modules/costs/db/migrate/20250709090813_add_entity_index_for_costs.rb b/modules/costs/db/migrate/20250709090813_add_entity_index_for_costs.rb
new file mode 100644
index 00000000000..2e32922eb8a
--- /dev/null
+++ b/modules/costs/db/migrate/20250709090813_add_entity_index_for_costs.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddEntityIndexForCosts < ActiveRecord::Migration[8.0]
+ disable_ddl_transaction!
+
+ def change
+ add_index :time_entries, %i[entity_type entity_id], algorithm: :concurrently
+ add_index :time_entry_journals, %i[entity_type entity_id], algorithm: :concurrently
+ add_index :cost_entries, %i[entity_type entity_id], algorithm: :concurrently
+ end
+end