Question

How to use database_url in App Platform

Posted March 17, 2021 473 views
DigitalOcean Managed MySQL DatabaseDigitalOcean App Platform

I am trying to connect the Database on the App Platform and I don’t see anything happened. Connection is not successful.

Env Vars Not Recognized

Description: I have an App Spec:

databases:

  • engine: PG name: db num_nodes: 1 size: db-s-dev-database version: “12” name: portal region: nyc services:
  • dockerfile_path: Dockerfile envs:
  • key: DATABASEURL scope: RUNANDBUILDTIME value: ${db.JDBCDATABASEURL}
  • key: DATABASEUSERNAME scope: RUNANDBUILDTIME value: ${db.USERNAME}
  • key: DATABASEPASSWORD scope: RUNANDBUILDTIME value: ${db.PASSWORD}

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hello,

Got to know the below points.

Currently, DATABASE_URL (or any other database bind variables) is not available during build. We plan on supporting build time access to databases soon though we don’t have any ETA. I apologize for the inconvenience caused!

Please change the scope of the Database variables to

databases:
- engine: PG
name: db
num_nodes: 1
size: db-s-dev-database
version: "12"
name: portal
region: nyc
services:
- dockerfile_path: Dockerfile
envs:
- key: DATABASE_URL
scope: RUN_TIME
value: ${db.JDBC_DATABASE_URL}
- key: DATABASE_USERNAME
scope: RUN_TIME
value: ${db.USERNAME}
- key: DATABASE_PASSWORD
scope: RUN_TIME
value: ${db.PASSWORD}

This should work! Hope this helps!

Cheers,
Sri Charan