Skip to content

Commit

Permalink
Rewrite migration using plain SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Aug 5, 2024
1 parent a144d66 commit 45dbe84
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions db/migrate/20211117195121_remove_destroyed_help_texts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check notice on line 31 in db/migrate/20211117195121_remove_destroyed_help_texts.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] db/migrate/20211117195121_remove_destroyed_help_texts.rb#L31 <Rails/SquishedSQLHeredocs>

Use `<<~SQL.squish` instead of `<<~SQL`.
Raw output
db/migrate/20211117195121_remove_destroyed_help_texts.rb:31:13: C: Rails/SquishedSQLHeredocs: Use `<<~SQL.squish` instead of `<<~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
Expand Down

0 comments on commit 45dbe84

Please sign in to comment.