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.
Related
I am currently doing the Ruby on Rails tutorial by Michael Hartl. Somewhere along the way I messed up my database. In my database file there is only 1 user, by the name of Bob.
Locally in cloud9 IDE, when I do 'rails console' and then do Users.first, I get a user with a name of "Bob".
However when I do 'heroku rails run console' and do Users.first, I get a user with a different name. (I probably changed the name somewhere along the way)
How do I get Heroku to see the correct local database file again? Should I clear the heroku database, then use pg:pull to pull the local sql database to heroku?
Not sure if you've gotten to Chapter 9 yet but section 9.3.2 of the current book deals with creating sample users. This is done through the db/seeds.rb file.
Running $ bundle exec rake db:reset then resets your DB followed by $ bundle exec rake db:seed to fill it with your new data.
You can run the same procedure on your production application with:
heroku pg:reset DATABASE
heroku run rake db:migrate
heroku run rake db:seed
It is, of course, also possible to transfer data between local and production databases with tools such as heroku-pg-transfer but that's a little advanced if you're only starting out, and I think somewhat unnecessary if you only have one user to transfer over.
Hope this helps.
You can use yaml_db gem to dump your local data to file and then upload it to heroku.
On your development machine:
rake db:data:dump
Then commit changes, push to heroku and run:
heroku run rake db:data:load
I have facing problems with migrating data to my heroku app which has Postgresql as database for my hosted site(Production). At my development site i have rails 3.2.13 with Sqlite3 as database. I have followed Ruby on rails Tutorial by Michael Hartl
i have used git push heroku to update my site at heroku. i also want to update database along with data. But heroku run rake db:migrate migrates schema not data. I tried db:push to push data to heroku but i get error
dependency.rb in 'to_specs' :Could not find sequel (~) 3.20.0
also i have searched and found that i should first my sqlite data to dump.sql and then run
heroku pg:psql HEROKU_POSTGRESQL_COLOR --app app_name < file.sql as answered in https://stackoverflow.com/questions/15371394/...
but it failed with
the local psql command could not be located
please tell me what i am doing wrong. or what is the right way to update heroku postgresql with my development sqlite3 data.
Thanks in Advance
It is not a good idea to fill the production database with the data that you have now in the developement database. Because, if you have problems with your production database in the future, and you need to refill it again, your development db may changed (e.g dropped), and you are not going to be able to do it again.
For this need, Rails provides seeds in db/seeds.rb file. You should create all the neccessary objects there.
Then when you push your code to Heroku, Heroku is going to prepare the database, create the schema, and seed it. If you need to seed the db manually, you can run bundle exec rake db:seed, if you want to run it in Heroku: heroku run bundle exec rake db:migrate
Recently I hosted my Ruby on Rails application on Amazon EC2 using Elastic Beanstalk. Everything works fine except my seeds.rb file. My seeds.rb file is not executed at the time of hosting. I am using ActiveAdmin also and I define first admin on my seeds.rb file.
How can I create first admin user on Amazon by rails console? Is there any way to open Rails Console on Amazon EC2 ? I am trying to do this using putty but don't know how to do this. Please give me some pointers..
Are you not supposed to do something like this?
# .ebextensions/bundles_container.config
container_commands:
01-bundle-install:
command: "bundle install"
leader_only: true
02-bundle-db-migrate:
command: "bundle exec rake db:migrate"
leader_only: true
03-bundle-db-seed:
command: "bundle exec rake db:seed RAILS_ENV='staging'"
leader_only: true
You can also pass parameters if needed, or combine all those commands with "cmd1 && cmd2".
You need to create keypair to access the amazon instance(which i think you already have). Make sure that ssh access is enabled in the current selected security group.
You can connect to the amazon instance using
ssh -i path/to/keypair.pub ec2-user#ec2-an-ip-address.compute-1.amazonaws.com
Then cd into the app directory and run bundle exec rake db:seed RAILS_ENV='staging' assuming that you're running the app in staging environment.
In case you're here and the above solutions didn't work for you.
Apart from using the command provided in this answer above by benchwarmer:
https://stackoverflow.com/a/17232607/1216245
I had to run the seed command providing env vars for the master key and all rds settings.
bundle exec rake db:seed RAILS_ENV=production RAILS_MASTER_KEY=<your master key> RDS_HOSTNAME=<your rds hostname> RDS_PASSWORD=<...> RDS_USERNAME=<...> RDS_DB_NAME=<...> RDS_PORT=<...>
And it worked, finally :)
You can check all this in the Configuration panel for your environment in the AWS console (dashboard).
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
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")