Class: RuboCop::Cop::Migration::RenameTable

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/migration/rename_table.rb

Overview

Do not rename tables. It will cause down time in your application and is unsafe for pt-online-schema-change. Instead:

  1. Create a new table
  2. Backfill and write to the new table
  3. Drop the old table

Examples:

# bad
class RenameUsersToAccouts < ActiveRecord::Migration[7.0]
  def change
    rename_table :users, :accounts
  end
end

# good
class AddAccounts < ActiveRecord::Migration[7.0]
  def change
    create_table :accounts do |t|
      t.string :name, null: false
    end
  end
end

class RemoveUsers < ActiveRecord::Migration[7.0]
  def change
    remove_table :users, if_exists: true
  end
end

Constant Summary collapse

MSG =
"Do not rename tables. It will cause down time in your application " \
"and is unsafe for pt-online-schema-change."

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



39
40
41
42
43
# File 'lib/rubocop/cop/migration/rename_table.rb', line 39

def on_send(node)
  return unless rename_table?(node)

  add_offense(node)
end