I'm totally new to Heroku and Postgres and I'm trying to figure out how to setup and access the Postgres db in a Heroku Ruby app.
I'm not sure how to go about setting this up. I've found some information about using the command:
rake db:create
Where do I enter this command? I'm completely in the dark on this.
Any help with how to setup/access the Postgres db in Heroku would be greatly appreciated.
Thanks.
Without info on what type of Ruby app you're building, what gems you may be utilizing, or what frameworks you may be building on, it is impossible to completely guide you through how to connect your Ruby app to the Heroku Postgres database. But here are a few things to point you in the right direction:
Install the Heroku Toolbelt as #jordan.baucke suggested. Beyond just adding plugins, you'll be using this toolbelt for nearly every Heroku-related action. Just follow the link, download, and install. Easy!
Now that you have the toolbelt, login to your account from the command line: heroku login.
Now make your app. While in your app folder (on the command line), execute: heroku apps:create <app name> -s cedar.
Now add the Postgres db: heroku addons:add heroku-postgresql:dev -a <app name>
From Ruby, you can connect to the db through the environment variable: ENV['DATABASE_URL'].
Deploy the app via git: git push heroku master.
From here, we really can't give you any further guidance since we don't know how you're interfacing with Postgres. But the above steps should at least get you to be able to connect to the db from your Heroku app.
For starters, are you using the the Heroku toolbelt? (command line tools?)
You can do it from the website as well, but with the toolbelt, you can enter heroku addons:add heroku-postgresql:dev --app *your app name*
Heroku will automatically inject the database into your app's database.yml when you deploy your app into Heroku.
Finally, you need to migrate the production database to your current migrations. You can do this remotely with the toolbelt again:
$ heroku run rake db:migrate
This will remotely connect a console and pull your migrations into your production database on the server.
Related
I have installed heroku with homebrew in my OSX El Capitan(10.11.5) and installed the heroku-container-tools with:
heroku plugins:install heroku-container-tools
The installation goes successfully:
Installing plugin heroku-container-tools... done
When I run a heroku version, I got this:
heroku-toolbelt/3.42.22 (universal.x86_64-darwin15) ruby/2.0.0
heroku-cli/5.2.20-9d094b0 (darwin-amd64) go1.6.2
=== Installed Plugins
heroku-container-tools#3.0.0
But when I run a heroku container:init I got this:
! `container:init` is not a heroku command.
! See `heroku help` for a list of available commands.
Running heroku help container I got this:
Usage: heroku container
Use Docker to build and deploy Heroku apps
Use Docker to build and deploy Heroku apps
Additional commands, type "heroku help COMMAND" for more details:
container:login # Logs in to the Heroku Docker registry
container:push [PROCESS] # Builds, then pushes a Docker image to deploy your Heroku app
I am following this heroku tutorial: https://devcenter.heroku.com/articles/local-development-with-docker
In the tutorial is said to run heroku container:init
This command was replaced but some other and heroku did not updated their documentation or I have some problem installing the plugin?
Yes, they restricted access to their container registry, just read the warning on top of the tutorial you're following https://devcenter.heroku.com/articles/local-development-with-docker
heroku container:release, which creates a Heroku-compatible slug and
deploys it to Heroku, has been deprecated. For access to our container
registry (available in private beta), please contact
docker-feedback#heroku.com
now there are only login and push commands. I hope you can easily ask for the access.
When I use the command heroku addons create:graphenedb --version v195. It gives error "No app specified , Run this command from an app folder or specify which app to use." I am new to Heroku and I do not understand which app folder it is talking about.
If you're not in your project folder or if it doesn't have a git remote to point it to Heroku you need to use the --app flag for the heroku command to specify the name of your app on Heroku
I'm having the same problem as this person: Heroku db:pull error "LoadError: cannot load such file -- sqlite3 (Sequel::AdapterNotFound)" Where I cannot pull my database from heroku.
However gem install sqlite3, gem install taps, and installing heroku toolbelt did not solve the problem in my case. Do I need to install something else?
I don't know if this affects the problem, but I have 2 apps on my local machine. Each logs into a different Heroku account, each Heroku account has a different login email address. I'm logged into the Heroku account with the database I want. When I enter git remote -v, the correct app name is returned. So I'm pretty sure my local computer is trying to to access the correct database on heroku.
If you are going to use Posgres remotely, you should be using Postgres locally. db:pull and db:push are not recommended. You should use pgbackups to export your data:
https://devcenter.heroku.com/articles/heroku-postgres-import-export
Your multiple accounts is likely not a factor here; you would receive an authentication error, not gem errors.
I was able to get a .dump file of my old database with pgbackups, then was able to convert to a text file with pgAdminIII.
I have to load pg_dump and the pg_restore to Heroku so that I can load a local database to Heroku. How can I install pg_dump and pg_restore on Heroku? What are their addresses?
So they way Heroku works is you install an addon to your Heroku app called Heroku Postgres. Then you add another app called PGBackups. These apps expose commands to your command line. They are like subcommands to the heroku command. So you'd do heroku pgbackups:restore to restore (or really, load initially) a database to your Heroku instance. See this link:
https://devcenter.heroku.com/articles/heroku-postgres-import-export
I am using Heroku and normally I do commands like:
heroku run rake db:reset --app myapp
which resets my database. I have read online that Heroku didn't support all rake commands (including db:reset, but the article may be outdated? as it works fine for me)
However, I have a production app and a staging app and am concerned about my late night programming, with regards to an accidental hit of db:reset on my production app.
Is there a way i could implement a prevention confirmation with a command like:
heroku run rake db:reset --app myapp or heroku run rake db:migrate --app myapp
or
git push production?
Be very careful when running any destructive commands. Just incase use https://devcenter.heroku.com/articles/pgbackups to make sure you can recover data if you do accidentally drop the database.