Class: RuboCop::Cop::Gusto::ExecuteMigration

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/gusto/execute_migration.rb

Overview

Disallow ‘execute` (raw SQL) in migrations. Run raw SQL from a backfill rake task, or pass SQL options to `add_column`/`change_column` instead, so migrations stay reversible and schema-focused.

Examples:

# bad
def up
  execute("UPDATE users SET active = true")
end

# good
def up
  add_column :users, :active, :boolean, default: true
end

Constant Summary collapse

MSG =
"Do not use `execute` to run raw SQL in a migration. Run the query from a backfill rake task or pass the SQL options to the `add_column`/`change_column` method."
RESTRICT_ON_SEND =
[:execute].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



24
25
26
# File 'lib/rubocop/cop/gusto/execute_migration.rb', line 24

def on_send(node)
  add_offense(node)
end