user4584963
user4584963

Reputation: 2523

Where is migration status saved?

My question is very much related to this one Should I delete migration after rollback.

I had my original migrate file 20140731141350_create_users.rb

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :email
      t.string :password

      t.timestamps
    end
  end
end

To which I needed to add a salt column, so I created the migration 20140804125449_add_salt_colum_to_users.rb

class AddSaltColumToUsers < ActiveRecord::Migration
  def change
    add_column :users, :salt, :string
  end
end

But during development I realised the salt column wasn't necessary and performed

rake db:migrate:down VERSION=20140731141350

Now I am left with an unused 20140804125449_add_salt_colum_to_users.rb migrate file.

My question is if I don't delete this migration file, where is this "down" status of this migration saved to? The migration file says add_column so if I run a db:migrate again how will it know that this specific file was migrated down?

Upvotes: 1

Views: 1510

Answers (1)

jalkoby
jalkoby

Reputation: 379

db:migrate:down and db:rollback are similar. down reverts a database to a specified version, rollback - to the previous. To check is a migration applied Rails has a specific table called "schema_migrations" which stores timestamps of all applied migrations, so basically when you run db:migrate:down rails reverts the migration and remove the row from schema_migrations. So if you don't delete the migration file - rails will apply it in the next db:migrate

Upvotes: 2

Related Questions