gitlab-org--gitlab-foss/rubocop/migration_helpers.rb
Sean McGivern 1ab33b15d1 Add cop for use of remove_column
remove_column should only be used in the up (or change) step of a migration if
it's a post-deployment migration. Otherwise there will be downtime due to the
ActiveRecord column cache, which we can avoid by using the IgnorableColumn
concern in combination with a post-deployment migration.
2017-12-11 16:34:51 +00:00

17 lines
534 B
Ruby

module RuboCop
# Module containing helper methods for writing migration cops.
module MigrationHelpers
# Returns true if the given node originated from the db/migrate directory.
def in_migration?(node)
dirname = File.dirname(node.location.expression.source_buffer.name)
dirname.end_with?('db/migrate', 'db/post_migrate')
end
def in_post_deployment_migration?(node)
dirname = File.dirname(node.location.expression.source_buffer.name)
dirname.end_with?('db/post_migrate')
end
end
end