After pushing ActiveAdmin app to Heroku, DB empty - ruby-on-rails

I had a working Active Admin app working on my local server, but after pushing to Heroku all my database tables are empty. I tried running heroku run rake db:migrate and then heroku restart but these both accomplished nothing. The tables are there, but they are empty.
Thanks!

If you want to have your Heroku app have the same database as local then you would you need to push your local database via heroku db:push to Heroku. This will replace the contents of the tables on Heroku with your local copy so use it carefully.
EDIT: heroku db:push is now heroku pg:push, the former is deprecated.

Related

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?
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
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
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.

Can I push my data directly to Heroku without using PG Backup Add-on?

I have the database schema ready on my Heroku App, but I want to push my data directly from my local database to Heroku.
Heroku dev center says it can be done using PG Backup Addon and pg_dump.
Any other way of doing it?
You should use heroku db:push
$> heroku pg:push --help
Usage: heroku pg:push <LOCAL_SOURCE_DATABASE> <REMOTE_TARGET_DATABASE>
Push from LOCAL_SOURCE_DATABASE to REMOTE_TARGET_DATABASE
REMOTE_TARGET_DATABASE must be empty.

Specify app with heroku db:push

I often do heroku db:pull and it works great.
I have created a staging app, to review code changes on Heroku before deploying to the production app.
I wonder though how I push db data specifically to the staging app?
Will the follwing work? heroku db:push -a my-staging-app-name
heroku db:push -a my-staging-app-name
will only push your local data to heroku. but it has some problems
I suggest you to push production db directly to staging server
For that you need to get the URL from production and run following command.
heroku pgbackups:restore DATABASE 'db_dump_url' -a my-staging-app-name

Create a Record in Heroku Database

I just pushed my rails app to heroku, I actually have some fake data locally that I directly inserted into my table through rails console.
What is the equivalent of that in heroku, the tables are configured on heroku but there is no data.
I don't want to create a seed.rb in my db and then push it to github and then run rake db seed on heroku
can i do it manually?
You can enter your application console on heroku with:
heroku run rails console
Check out this gem. It is all ready dependency for heroku gem. With it bundled in your app you can do stuff like:
heroku db:pull
heroku db:push
Commands are quite self explanatory.

Rails Heroku Database Population

After deploying an app of Heroku I am having trouble getting the database populated with some of the data I need there. I ran heroku rake db:populate and it did create the initial admin user, but failed to put the rest of the data in.
I am populating the database with files from my local disk. I suspect the problem is caused because it sees nothing in the directory listed in the sample_data.rake file, as it in on my hdd and not the server. How can I get around this?
I figure that I have to either host all the files and change the directory to the servers directory, or find a way around this. I would guess there is an easy way to move the database from my computer to heroku? I'm obviously pretty new to this.
Thanks!
heroku commands have changed. now it should be:
heroku run rake db:push
heroku pg:reset DATABASE
heroku run rake db:seed
also data from local database can be uploaded to heroku by installing taps gem and pushing data from local PostgreSQL db.
gem install taps
heroku db:push
If you have a clean local database (i.e. just the good stuff, no silly testing data), then you could try heroku db:push:
db:push [<database_url>] # push a local database into the app's remote database
And please remember to develop on PostgreSQL if you're going to use the Heroku shared or dedicated databases, using the same database and version (version 8.3 for shared, 9.0 for dedicated) in both your development and production environments will save you much pain, suffering, and confusion.
References:
How can I import my existing data to Heroku?
Import: Push to Heroku
I setup the development db, and push it to Heroku.
rake db:reset
rake db:seed
heroku rake db:push
If you are using the default PostgreSQL, another option is heroku pg:reset
heroku rake db:seed
I use the following in the seed.rb file:
require 'pathname'
RailsRoot = Pathname.new(RAILS_ROOT).expand_path
print "Loading data..."
fileData = File.read (RailsRoot + "db/data-file.csv")

Resources