Skip to content

Files

Latest commit

 

History

History
50 lines (37 loc) · 937 Bytes

Rails-ReversibleMigrationMethodDefinition.md

File metadata and controls

50 lines (37 loc) · 937 Bytes

Pattern: Missing use of change or up/down for migration

Issue: -

Description

Checks whether the migration implements either a change method or both an up and a down method.

Examples

# bad
class SomeMigration < ActiveRecord::Migration[6.0]
  def up
    # up migration
  end

  # <----- missing down method
end

class SomeMigration < ActiveRecord::Migration[6.0]
  # <----- missing up method

  def down
    # down migration
  end
end

# good
class SomeMigration < ActiveRecord::Migration[6.0]
  def change
    # reversible migration
  end
end

# good
class SomeMigration < ActiveRecord::Migration[6.0]
  def up
    # up migration
  end

  def down
    # down migration
  end
end

Further Reading