0

I made a migration to remove a column from my first app ever about a week ago:

class RemoveHalfOrFullFromFurlough < ActiveRecord::Migration
  def up
    remove_column :furloughs, :half_or_full
  end

  def down
    add_column :furloughs, :half_or_full, :decimal
  end
end

I must have done something wrong because half_or_full is still in my schema. I didn't notice until today when I tried to add the Active Admin gem. It errors out because it's trying to pull data from this zombie-column and doesn't have any idea what to do with it.

I made a number of migrations since, so I didn't think a simple rollback is an option. Maybe it is?

This is the original migration that created the column:

class AddHalfOrFullToFurloughs < ActiveRecord::Migration
  def change
    add_column :furloughs, :half_or_full, :decimal
  end
end
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Alaric
  • 229
  • 1
  • 12

1 Answers1

0

Here's my philosophy for migrations:

While I'm in the development phase, the idea of a migration is that I can make a change in the up section, and reverse it in the down section. I can roll back to the start and roll forward to the top or stop midway, depending on my needs. I'm still "developing" the system, and I'm creating the rules about where my database needs to be at any point in time. (I control the horizontal. I control the vertical.)

As I debug migrations I sometimes roll-back a level or two then roll forward to fine tune the changes. Some people say we should only roll forward so it's all completely reproducible. I don't usually see sense in undoing a stupid step with another migration when the data is disposable, so I'll back up, tweak and take another run at it. Your, or other people's, mileage might vary.

Once I move from the development phase to testing and production the rules change. I roll forward to the end and stay there because my database and code should be pretty stable at that point and I'm loading data "for reals".

the Tin Man
  • 158,662
  • 42
  • 215
  • 303