views:

36

answers:

3

I have a development database on my computer and a production database on Heroku. I need to run a migration on the production database, to clear certain data, that I don't want to run on the development one. So far I've only been doing migrations that I've wanted to run on both, so I just create it on my computer, run it, then when I upload to Heroku I run it on there too. How can I do a migration only on the production database? Thanks for reading.

A: 

RAILS_ENV=production rake db:migrate

qichunren
+2  A: 
  1. Create your migration.
  2. Commit, push, run on heroku with heroku rake db:migrate --app myapp.
  3. Comment out the contents of the up block.
  4. Run the (now-empty) migration locally.
  5. Uncomment or git checkout/reset to get back to normal.

This way both your local db and production db will consider the migration to have been run and not try to run it again.

tfe
A: 

Migrations are intended to update the structure of your database, not to manipulate data. If you want to manipulate data, you should use the console or a script.

$ heroku console
Simone Carletti