I tried to use heroku-valkyrie to transfer my local data to heroku databse.
https://github.com/ddollar/heroku-valkyrie
I installed the plugin:
heroku plugins:install http://github.com/ddollar/heroku-valkyrie.git
Installing heroku-valkyrie... done
and wanted to transfer data:
heroku db:transfer sqlite://db/development.sqlite3 postgres://my-apps-database-url/
but received this error message:
! `db:transfer` is not a heroku command.
! See `heroku help` for a list of available commands.
How can I use db:transfer as a heroku command?
According to Heroku documentation, you will have to export your local database as a dump file by using the pg dump tool and import the file using command.,
heroku pgbackups:restore DATABASE 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump'
Check for complete documentation here
Try running heroku plugins:install https://github.com/ddollar/heroku-pg-transfer first.
Then the command will be pg:transfer, not db:transfer.
However, you may run into issues since you're transferring from an sqlite database and this command only transfers from postgre.
Related
so i've successfully installed Harrys Prelauncher on Heroku (https://github.com/harrystech/prelaunchr)
and to export my collected emails into a csv i need to run this command (bundle exec rake prelaunchr:create_winner_csvs)
is there any way to run that command through pgadmin or some other program?
or is the only way for me to download my heroku database and run the command locally? also how and what would i need to do this?
i'm pretty new to rails and postgresql and would really appreciate if someone could help me out!
Because the rake task creates files locally you can't just run it on heroku via heroku run rake. You can however set up your local database.yml to connect to your heroku postgresql instance and run the rake task locally.
Run heroku pg:credentials to get the required database values.
Fill in the production environment of config/database.yml with the values you obtained from step 1 (for the value of 'database' in the yml file, use dbnmae from step 1)
Test your connection with RAILS_ENV=production rails db. This should drop you into a psql console.
Run the rake task. RAILS_ENV=production bundle exec rake prelaunchr:create_winner_csvs
The files will save locally in lib/assets as indicated by the documentation.
From within the directory of the project you can use
heroku run rake prelaunchr:create_winner_csvs
You should probably create a UI form in to your application.
On click on export CSV, it should run background job on heroku (Using delayed jobs).
heroku run rake prelaunchr:create_winner_csvs
Use send_data ruby method. To send your generated and dumped data file on to your browser.
Download the file on to your local system from running heroku instance.
Hope this will resolve your problem.
Cheers!!!
I ran into this problem recently while developing the Prelaunchr campaign for a client. Assuming you have a local version of your app and are using Postgres Copper in Heroku, you can "pull" your Heroku database down to your local machine, set that as your development database in database.yml, and run the rake task from your local app, which should now have the same database as your heroku version. Here is the command to pull the db (subbing out name_for_database & heroku_app_name with your own):
heroku pg:pull HEROKU_POSTGRESQL_COPPER_URL name_for_database --app heroku_app_name
Make sure to restart your local server to see the new database info populated.
Can someone please help me how can i pull single table from heroku database.
I have tried the following way:
heroku db:pull --tables table_name
with no luck as heroku db:pull is deprecated now.
Thanks in Advance
Not sure if you can pull a single table from heroku but there are certainly some options to pull whole database.You can use Herokus PG Backups add-on to import or export your database. First you'll have to add it as add on in your app by
$ heroku addons:add pgbackups
$ heroku update
After that you can download your database by
$ heroku pgbackups:capture
$ curl -o latest.dump `heroku pgbackups:url`
You can also use pg:transfer Heroku CLI plugin to transfer the data in a single step.
From your app's directory, copy your production database locally (assuming a local PG db), by installing the plugin and execute the pg:transfer command.
$ heroku plugins:install https://github.com/ddollar/heroku-pg-transfer
$ heroku pg:transfer
Not sure if this is still relevant, but you can achieve what you want pulling a CSV dump of a single table (or any other format) and then import it. The steps would be as follows:
# 1. Connect to psql on Heroku
$ heroku pg:psql --app your_app_name DATABASE
Then you can download a table like so:
# 2. Pull table_you_want_to_copy
your_app_name::DATABASE=> \COPY table_you_want_to_copy TO '~/local/path/your_table.csv' WITH (FORMAT csv, DELIMITER ',', HEADER true);
A simple version of an importer could look like this:
# 3. Seed local table from fetched CSV
CSV.foreach('~/local/path/your_table.csv, headers: true) do |row|
YourModel.create(row.to_hash)
end
In this block you can ofc define whatever other logic you might require.
I have deployed Rails app to Heroku. App uses PostgreSQL for data management. It works fine locally. I am searching for a way to push my local PostgreSQL database to the Heroku database.
heroku pg:push command doesn't work for me. Complains about lack of local psql, which is there. So I have decided to use pgbackups add-on for this purpose. I have run pg_dump locally to create a database dump and put it into the public Dropbox folder.
When I try to pull it from heroku I get the following error:
heroku pgbackups:restore DATABASE "http://file.dump"
! An error occurred and your restore did not finish.
! Please run 'heroku logs --ps pgbackups' for details.
The problem is that heroku logs --ps pgbackups gives me nothing. I don't see any pgbackups associated logs in the Heroku log listing.
Am I doing something wrong? Do I need to turn on heroku add-on logs somehow?
P.S. I am able to run heroku pgbackups:capture and heroku pgbackups:restore, but I don't see any logs either.
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.
I have now my rails 3.2.1 app running on Heroku.
I've tried to upload the database to mongohq via the heroku mongo:push command, after installing the heroku mongo plugin.
https://github.com/pedro/heroku-mongo-sync
I get the message asking me to confirm if I want to push, but once the push is done, there is nothing my db.
I'm not sure if it is a problem with heroku or if i'm missing a step.
Could it be that i need to put my app in production mode and migrate the database to production?
I'm not sure how to do that either.
Cheers
does your local heroku connection conform to the plugins assumptions [in the readme's config section]? if not you'll have to set it via:
export MONGO_URL = mongodb://user:pass#localhost:1234/db
i'll also note, that even after doing this i had to uninstall the heroku plugin and reinstall it from this fork: http://github.com/fjg/heroku-mongo-sync.git
heroku plugins:install http://github.com/fjg/heroku-mongo-sync.git
Check out the MongoSync Ruby Gem
It's a gem I wrote for that very purpose when I had to constantly copy my Local MongoDB database to and from my Production DB for a Project (I know it's stupid). It's extremely easy to use. Once you've entered your DB details in the mongo_sync.yml file, you can push and pull DBs using these rake tasks:
$ rake mongo_sync:push # Push DB to Remote
$ rake mongo_sync:pull # Pull DB to Local
Note: It's also available as shell script for non-ruby apps: mongo-sync