0

I'm developing on my localhost using sqlite and deploying to Postgres on heroku, where the live app is already on heroku.

I've done a lot of development lately which includes several db structure migrations, so I've pulled the Postgres live database to my localhost to run the migrations locally to test (and swapped my local db to Postgres).

When I run rake db:migrate, it tries to run all the migrations from the beginning of time, rather than just the new ones.

How does rake know which migrations to run?

1
  • there is a table named 'schema_migrations' which has an entry for each migration that has previously been run on the database - try psql YOUR_DB -c "select * from schema_migrations" Commented Feb 22, 2014 at 21:33

1 Answer 1

0

When you migrate first time , then rake will run all the migration .

When you run db:migrate, rails will check a special table in the database which contains the timestamp of the last migration applied to the database. It will then apply all of the migrations with timestamps after that date and update the database table with the timestamp of the last migration. As a result, each migration class is applied exactly once to the database.

source: https://stackoverflow.com/a/6319952/1970061

previously your database was different i.e sqlite, but when you switched to postgres you created new database, hence all table must be created for new database therefore all migration is running

Sign up to request clarification or add additional context in comments.

5 Comments

OK, I understand. So if I export a database from heroku, how do I run only the latest migrations?
running latest migration , or all migration ..why do you care ? any way running migration create tables so what's wrong in creating tables ?
I'm applying the migrations to a real live database with data already in it
what do you mean by ..'you have pulled live data from heroku' ? do you have dump of psql ?
Yes that's right. It's a big live project and I want to test the migrations before I deploy them to live.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.