How can I run a migration on my production database but not my development database?
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 c开发者_运维百科lear 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.
- Create your migration.
- Commit, push, run on heroku with
heroku rake db:migrate --app myapp
. - Comment out the contents of the
up
block. - Run the (now-empty) migration locally.
- 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.
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
RAILS_ENV=production rake db:migrate
精彩评论