Skip to content

Fix false positives for Migration/SchemaAdditionMethodsNoPost cop

What does this MR do and why?

We allow add_column and create_table methods inside the down method in post-deploy migrations. But if these methods were wrapped inside a statement like if then the cop was raising an error. For example, in the following, the 2nd example was being incorrectly flagged as an offense:

def down
  add_column(:table, :column)
end
def down
  add_column(:table, :column) unless column_exists(:table, :column)
end

How to set up and validate locally

  1. Run spec/rubocop/cop/migration/schema_addition_methods_no_post_spec.rb on master and on this branch.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #414251 (closed)

Edited by Peter Leitzen

Merge request reports

Loading