doctopus
doctopus

Reputation: 5647

Deploying to Heroku with existing data

Currently on Ch 2 of Hartl's tutorial in which I make a simple app with users and microposts.

I add a few users and microposts to the database.

Near the end of the chapter, it gets you to deploy the app to Heroku. When I view the app on Heroku however, there are no users or microposts anymore.

How do I get the existing data to be deployed as well?

Upvotes: 0

Views: 114

Answers (3)

bkunzi01
bkunzi01

Reputation: 4561

If you're using postgres you can push your local database to your heroku app doing the following:

Checkout your config/database.yml file to see what the development database is named. For this example I'll call it cool_development. Then once you have run:

git push heroku master

Then run the migrations to create the database: heroku run rake db:migrate Then push your database to heroku: heroku pg:push cool_development DATABASE_URL --app app_name_here

The database heroku creates for you is accessed using the DATABASE_URL environment variable so you don't need to change anything in the above line except for the local database name unless your app is named 'cool' lol.

Upvotes: 0

Zain Zafar
Zain Zafar

Reputation: 1607

Use YamlDb gem to dump data to a yaml file.

Create data dump by:

rake db:data:dump   ->   Dump contents of Rails database to db/data.yml

Push code to Heroku:

git push heroku master

Load data to heroku database:

heroku run rake db:data:load   ->   Load contents of db/data.yml into the database

Upvotes: 1

Kevin Etore
Kevin Etore

Reputation: 1124

Heroku has different database than your app locally. So every data you created in the local app will not be pushed to Heroku when you run git push heroku master

I would create a database dump (maybe the Seed Dump is interesting) so you can import this in Heroku or you could place the users and microposts in a seed file and run heroku run rake db:seed

http://railscasts.com/episodes/179-seed-data gives an brief explanation on how you could seed the db

Upvotes: 1

Related Questions