I deployed an app onto heroku and wanted to check how can I connect to the deployed app in my terminal so I can do things like run migrations?
thanks in advance!
You can use the heroku command to create a one-off dyno to run arbitrary commands like bash or rake db:migrate.
For example heroku run bash -a my-app will run a bash shell on a one-off dyno.
Note that there is no way to directly connect to a running dyno on Heroku (e.g. via ssh); running the heroku run command will create a new temporary dyno that you can use to run commands using the deployed version of the code.
Related
Is it possible to run heroku-cli-commands like heroku regions from the Heroku Dashboard?
I tried to run those in the console, but it did not work..
From the heroku explanation page, as well as the appearance of the console, it seems that you can only run commands that start with heroku run (Example: npm start).
That means you can run commands there for the app, and heroku will pass them to it. Like you could run if the app was running on your computer. But do not run regular heroku cli commands, for example install an add-on, through the dashboard on the website, but only through heroku cli
I am trying to schedule PostgreSql procedure using Heroku scheduler. I tried heroku pg:psql -c "call procedure_name();" --app app-name but gets the error from scheduler "bash: heroku: command not found"
That error is telling you important information. The Heroku CLI is not present in your environment, so bash complains that heroku isn't a command that it recognizes.
If you want to run heroku commands from your application you'll need to include the cli buildpack when you build your application to make sure it's properly bundled. Once you've included the buildpack and triggered a new build, this should work.
I'm trying to change some data on heroku that I normally do with iex -s , but the following command does nothing.
heroku run iex
The command that worked was
heroku run iex -S mix
When dealing with phoenix project just use:
heroku run iex -S mix phoenix.server
To launch the server in your iex console
or simply
heroku run iex -S mix
to compile the files without starting the server.
Note that if you deploy your app to Heroku using the native release mechanism that comes with Mix since Elixir 1.8, you may simply ssh into the running dyno and remote into the running BEAM node:
# In your local terminal
heroku ps:exec
# In the dyno
_build/prod/rel/your_app/bin/your_app remote
This works out of the box.
I am trying to run bash on heroku to test it out and it is failing
$ heroku run bash
▸ Error: No app specified
▸ Usage: heroku run --app APP
▸ We don't know which app to run this on.
▸ Run this command from inside an app folder or specify which app to use with --app APP
▸
▸ https://devcenter.heroku.com/articles/using-the-cli#app-commands
$ heroku run --app bash
▸ Usage: heroku run COMMAND
▸
▸ Example: heroku run bash
So, the example says heroku run bash will work but it doesn't. I have no dynos running. I feel I am missing something basic here...
Try run commands:
First you need to login, then you to see your apps and finally run bash
heroku login
Insert you user and password
heroku apps
=== user#gmail.com Apps
myaplication
then look at the list apps and write
heroku run bash --app myaplication
You could also do this:
get app name using;
heroku apps
then set heroku remote;
heroku git:remote -a yourappname
and finally run bash on/in your app
heroku run bash
I think you have two issues.
Firstly, you need to run bash within some app. You can either specify the app via the --app key as the help actually says or you can run this command inside the folder which has a heroku app initialized already. For connecting the folder to a heroku app - see this answer How to link a folder with an existing Heroku app.
Second, running a bash actually takes away one dyno from your app. So you need to have at least one dyno.
Try this command:
heroku pg:psql -a appname
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.