diff --git a/db/migrate/20211117195121_remove_destroyed_help_texts.rb b/db/migrate/20211117195121_remove_destroyed_help_texts.rb index 01f24e1c5985..ad219639e5b7 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