Skip to content

Fixes Rubocop Migration/AddLimitToTextColumns failures

What does this MR do and why?

Solves: #388821 (closed)

It circuit-breaks array_column?(node) method when the node is not of the type RuboCop::AST::SymbolNode.

This rule is intend to work when adding a new array column in post-migrations.

Ex:

class AddNewArrayColumn < Gitlab::Database::Migration[2.1]
  def up
    add_column :my_column, :numbers, :integer, array: true, default: []
  end

  def down
    # no-op
  end
end
bin/bundle exec rubocop db/post_migrate/add_new_array_column.rb

C: Migration/SchemaAdditionMethodsNoPost: This method may not be used in post migrations. Please see documentation here: https://docs.gitlab.com/ee/development/migration_style_guide.html#choose-an-appropriate-migration-type

How to set up and validate locally

  1. generate a new post-migration file:
    rails g post_deployment_migration TestRubocopMigration
  2. change the migration's body to include:
    column = :partition_id
    
    define_batchable_model(:ci_build).where(column => 100)
  3. execute rubocop
    bin/bundle exec rubocop db/post_migrate/migrationnumber_test_rubocop_migration.rb
  4. In master this should raise and error
  5. In 388821-rubocop-migration-addlimittotextcolumns-failures branch, this should not raise any error

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 #388821 (closed)

Edited by Leonardo da Rosa

Merge request reports