I started by defining a framework ID as specified here
http://www.playframework.org/documentation/1.2/guide11
I called my server appnameheroku
Then I retrieved the database URL using
heroku config
from the console
I then added the following two lines to application.conf
%appnameheroku.jpa.ddl=validate
appnameheroku.db=postgres://....compute-1.amazonaws.com/etc
I then deploy the app and get the following error
Oops, an error occured
This exception has been logged with id 6963iilc8. I'm using the free version of Heroku.
Two things here: Storing config in the application code is a bad idea, as it prevents Heroku from carrying out a lot of administrative tasks on your behalf.
Therefore I would configure my application.conf as:
db=${DATABASE_URL}
jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
jpa.ddl=update
Heroku don’t recommend setting jpa.ddl to update for a real world production app. Use Play!’s database evolutions instead.
Related
I tried to deploy a keystone app to Heroku and I did it but while I tried to open the app I got the following error:
An error occurred handling a request for the Admin UI: Error: Prisma error: The table main.User does not exist in the current database.
Here's a screenshot containing more details about the error:
I tried to locate the database and create the User table.
I expect to know the steps of how to solve this issue.
It looks like your DB hasn't been initialised properly. The error you've included is failing to count the items in the User list which (if you don't have sessions configured) is likely the first query to run – a count of items in each list is shown on the Admin UI the landing page so that's the first thing it does.
So something about how your migrations are being generated or applied in production isn't setup right. Most of the relevant docs on how this works are in the CLI guide, specifically, see the section about database migrations and the db.useMigrations flag.
Having db.useMigrations turned off can be handy if you're just playing around in dev. Keystone will automatically sync your DB structure to what's defined in your list configs whenever it starts, and does so without creating any physical migration files. If you're prototyping some change or just mucking around, this may be what you want but – if you're deploying somewhere – better to turn db.useMigrations on. Then, if Keystone detects changes to the DB when it runs, it'll prompt you to create a migration file, which can be tweaked to protect existing data if needed, tracked under version control (eg. git) and deployed.
Getting these migrations to run in an environment like Heroku is a little slightly weird as (assuming it's enabled for your app) Heroku can auto-scale. Migrations on the other hand need to be run exactly once. You also can't just lock the DB and run migrations when the first instance of the app starts – this delays the start up of the HTTP server so, if the migrations run for too long, Heroku may think the deployment has failed.
The way we suggest getting around this is to run migrations in the build staging. Fans of the 12-factor app methodology will notice this violated the separation of build and release stages but, for a simple Heroku deploy, it works fine. For larger/more serious apps, creating and applying migrations usually an area that needs significant thought and attention. The specific infrastructure and rollout processes required will be project dependant.
I'd also encourage you to check out the Keystone 6 Heroku example codebase if you haven't already. It's a little out of date but it shows the migrations and package.json scripts in action.
Heroku sent an email regarding scheduled maintenance for a hobby-dev hosted Postgres database I have. I received confirmation that the scheduled maintenance had been successfully completed and that my updated database credentials would reflect this.
After updating the environment variables in my app to reflect this change, I can no longer connect to the database. Scheduled maintenance changes have completed before with no issues, this is the first time I'm receiving this error.
Authentication failed against database server at `ec2-176-34-114-78.eu-west-1.compute.amazonaws.com`, the provided database credentials for `mydb` are not valid.
However, when I log into Heroku to view the database instance, the health checks are showing that it's available.
I've now tried using the new and old database credentials, but both are unable to connect to the DB. It also appears that I am unable to directly contact support on the hobby dev plan.
Do I have any other options to try troubleshoot this? Is it possible to force a new database credential update on Heroku?
Yes, you can use heroku pg:credentials:rotate to generate new credentials. But you shouldn't have to do this.
After updating the environment variables in my app to reflect this change
As the email told you, your credentials would automatically have been updated. There was nothing for you to do. As long as you are connecting via the DATABASE_URL environment variable, which is always recommended with Heroku Postgres¹, you should be good to go.
heroku pg:credentials:rotate behaves the same way, so running that command without understanding this isn't likely to help much.
¹Heroku may update these credentials at any time. Connecting via that environment variable is the best way to ensure you can always connect.
Heroku provides its own database name and other credentials, but my local database name is different.How can I change the database name according to the database credentials provided by heroku during production?
Use a package like dotenv. dotenv and variants of it likely exist for whatever language you're using.
Basically, you want to use environment variables instead of hard coding values into your code. So, instead of writing something like this:
my_database_connect('my_username', 'abc123')
You'd write:
my_database_connect(process.env.DB_USERNAME, process.env.DB_PASSWORD)
Heroku will already have these environment variables set on the "config" tab of your app. Then for local development, you'll create a file called .env and have this text in it:
DB_USERNAME=my_username
DB_PASSWORD=abc123
Don't commit .env to your git repository – it should only live on your machine where you develop. Now your code will run locally as well as on Heroku, and connect to the proper database depending on the environment it's running in.
Here's an article that explains this more thoroughly for node.js, although this is basically the best practice for general development: https://medium.com/#rafaelvidaurre/managing-environment-variables-in-node-js-2cb45a55195f
First I created an application name on Heroku. Then I deployed my app to heroku by connecting to github.
Heroku provides the database credentials after we deploy our applications. Then I redeployed the app through github by changing the configuration in application.properties file as follows:
#localhost configuration
SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
SPRING_DATASOURCE_URL=jdbc:postgresql://localhost/transactions?useSSL=false
SPRING_DATASOURCE_USER=postgres
SPRING_DATASOURCE_PASSWORD=some_pass
#server database configuration
SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
SPRING_DATASOURCE_URL=jdbc:postgresql://ec2-23-23-247-222.compute-1.amazonaws.com/d6kk9c4s7onnu?useSSL=false
SPRING_DATASOURCE_USER=rimjvlxrdswwou
SPRING_DATASOURCE_PASSWORD=dd903753bc0adffb96ce541b1d55fb043472e32e28031ddc334175066aa42f69
Then you have to edit the config vars according to your application.properties files as shown in the figure below
config_var.png
I have tried deploying mean stack application to Heroku, but when I visit the URL:
https://rocky-coast-36852.herokuapp.com/%20deployed%20to%20Heroku
It's showing the error:
Cannot GET /%20deployed%20to%20Heroku
Also while trying to connect to mongoose database it showing the error:
error in database connectonMongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
(node:42332) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
Here is my GitHub link:
https://github.com/saisreereddy/MyFirstApp
Can someone please identify where I doing wrong?
Any kind of help is highly appreciated.
This line would seem to be the cause of your problem:
mongoose.connect('mongodb://localhost:27017/contactlistapp');
Presumably, your database is not running on your Heroku dynos and you're using a Heroku hosted database add-on, like MLab. (If not, provisioning a Mongo add-on is the first step in your solution.) When this add-on is added to your application, it will set an environment variable like DATABASE_URL (refer to add-on documentation), which will contain the database url, username, password, etc.
You'll want to change that line above in app.js to pull that value from the environment using something like mongoose.connect(process.env.DATABASE_URL);, which should just work on Heroku.
Now, you'll also need to set that environment variable locally, using the value you currently have hardcoded in app.js. I'd suggest using dotenv to handle setting the local env vars. If you do use dotenv, be sure to add .env to your .gitignore file.
I am setting up a Laravel 5 openshift application but every time i had the database code in project it says whoops something missing. I have added the environment in .env as in my database credential an still no success. I am wondering what may be the cause of this since I followed all instruction the website is working but only if I omit my database code.
Are you trying to get your database working for local or remote development? The .env file in the root directory is for local development, while the .openshift/.env file is for remote development. If you're using an standard OpenShift database (such as MySQL or PostgreSQL), you shouldn't need to make any configuration changes to get the database working. It's already configured via environment variables.