grg-n-sox
grg-n-sox

Reputation: 717

In Rails, how do I go over a db migration without executing it?

So I jumped onto this Rails project at work and I have my own copy of it running on my local devbox. I tried to run the tests to see what the results were but rake came back complaining that I had 5 outstanding migrations to do first. I first just tried running rake db:migrate but that didn't work due to the migrations trying to create tables that already existed. It was then I realized that these migrations have already been run, but for some reason it thinks it is currently at an older migration.

Is there any way to make Rake move forward in the migration history without doing a rollback and redoing the migration?

Upvotes: 0

Views: 562

Answers (2)

usha
usha

Reputation: 29349

You could update schema_migrations table to have the migration numbers that you want to skip. That's the table rails uses to keep track of the migrations that have been run already.

select * from schema_migrations

will give you something like

   version     
----------------
 20121026165533
 20121026183631
 20121212144141
 20130205205009

Add the migration numbers that you want to skip to this table.

Upvotes: 1

Emile Victor
Emile Victor

Reputation: 933

You could either:

  1. Delete the migrations in question, make a new set of migrations to take their place (dangerous)

  2. Do the rake db:reset as you mentioned.

I would only suggest 1 if you are the only developer on the project. In reality however, your migrations and seeds should be in such a state as to not warrant this.

I would implore you to take #2, as #1 could result in issues down the track. Your copy of the database should be representative of what you would get if you ran rake db:reset anyway.

Upvotes: 0

Related Questions