Migration/SchemaAdditionMethodsNoPost cop raises false positives
If the add_column
or create_table
methods are defined in the down method inside a post-deploy migration then the cop doesn't flag any offense which is correct according to our guidelines https://docs.gitlab.com/ee/development/migration_style_guide.html#choose-an-appropriate-migration-type.
But if we wrap these methods inside a statement like an if statement then the cop raises a false offense. In both of the examples below, the cop shouldn't raise anything:
def down
add_column(:table, :column)
end
def down
add_column(:table, :column) unless column_exists(:table, :column)
end
But it does raise an offense for the 2nd example.
The following discussion from !122425 (merged) should be addressed:
-
@ghavenga started a discussion: (+1 comment) Thought (non-blocking): This is interesting. I can't imagine why this cop would flag here in the first place, except that it's not able to detect that the column use is inside the
down
method.🤔