4

Following on from my previous post (carrierwave image not loading into source code), I've added a new column (feature_image) to my table portfolios.

I would like to push this to my Heroku app however I already have a number of portfolio entries on the website that I don't want to lose.

Is there anyway I can push my database changes without losing the content already on there?

Thank you!

Community
  • 1
  • 1
  • pushing it will not affect your records, only new migration will run to add new column so you'll end up having lots of portofolios with no image – rmagnum2002 Jan 14 '14 at 13:25

1 Answers1

2

pushing it will not affect your records (unless you have some special code that resets the db each time you do a push - never heard of such cases, but who knows), only new migration will be executed to add new column so you'll end up having lots of portofolios with no image.

rails app saves all migrations numbers into schema_migration table in db, so next time you'll run a migration it will migrate only the ones that are not in schema_migration.

in my case if I'll run migration only 20140109214830_add_is_new_to_messages will be migrated as its number is not schema_migration, it works this way on local machine and the same when pushing.

enter image description here

after migrating it, migration number will be saved into schema_migration table (line 44):

enter image description here

git push heroku master && heroku run rake db:migrate && heroku restart

rmagnum2002
  • 11,341
  • 8
  • 49
  • 86
  • So if I have 20140114071826_add_feature_image_to_portfolios, do I do heroku run rake --trace db:migrate VERSION=0140114071826? @rmagnum2002 – Luchia Bloomfield Jan 14 '14 at 13:37
  • do you need trace? I think `heroku run rake db:migrate` should be enough and no need to specify the migration number unless you want to migrate a specific one, for example you have migrations with numbers 1, 2, 3, 4 and you want to migrate number 3, in this case you specify the migration number.. In your case you are running migration for all that are not in `schema_migration`... so `heroku run rake db:migrate` is what you need.. it will skip the existing ones, and will migrate the new ones only – rmagnum2002 Jan 14 '14 at 13:41
  • also you might need to push changes to heroku first and then run migrations... something like `git push heroku master && heroku run rake db:migrate` in one line. – rmagnum2002 Jan 14 '14 at 13:43
  • Yeah I did the push first, then the migrate. Hmmm, getting the 'We're sorry, but something went wrong.' Checked my local version - can add a new portfolio/edit existing portfolio to include a feature image fine, rake tests are fine. Any thoughts? – Luchia Bloomfield Jan 14 '14 at 13:46
  • join this http://chat.stackoverflow.com/rooms/45200/http-stackoverflow-com-questions-21114592-add-new-column-to-table-push-to-herok – rmagnum2002 Jan 14 '14 at 13:47
  • Here's the pastebin - don't have enough rep yet to talk in chat. http://pastebin.com/DVDyNqgb – Luchia Bloomfield Jan 14 '14 at 13:50