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

Rewrite migration using plain SQL

Oliver Günther45dbe841beb8
diff --git a/db/migrate/20211117195121_remove_destroyed_help_texts.rb b/db/migrate/20211117195121_remove_destroyed_help_texts.rb
index 01f24e1c598..ad219639e5b 100644
--- a/db/migrate/20211117195121_remove_destroyed_help_texts.rb
+++ b/db/migrate/20211117195121_remove_destroyed_help_texts.rb
@@ -28,14 +28,14 @@
class RemoveDestroyedHelpTexts < ActiveRecord::Migration[6.1]
def up
- custom_field_ids = CustomField
- .pluck(:id)
- .map { |id| "custom_field_#{id}" }
-
- AttributeHelpText
- .where("attribute_name LIKE 'custom_field_%'")
- .where.not(attribute_name: custom_field_ids)
- .destroy_all
+ execute <<~SQL
+ DELETE FROM attribute_help_texts
+ WHERE attribute_name LIKE 'custom_field_%'
+ AND attribute_name NOT IN (
+ SELECT CONCAT('custom_field_', id)
+ FROM custom_fields
+ )
+ SQL
end
def down