Ruby

Ruby

Made by DeepSource

Rails migrations are not reversible RB-LI1107

Anti-pattern
Major

ActiveRecord migrations should be reversible, by implementing either a change method, or both an up and a down method.

Bad practice

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

Recommended

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

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

  def down
    # down migration
  end
end

References

  1. Dissecting Rails Migrations
  2. Why Reversible Migrations Are Important and How to Write Them?