Connect an app to a database or app
Connect an app to a database or to another app in the same project, and the app reads the connection details from a variable. Orchard stores a reference instead of a copied value, so the variable stays correct after a password rotation or a restore, and you never paste a password by hand.
A reference has this format:
${{resource.<connection>.<field>}}Prerequisites
Section titled “Prerequisites”- Edit access to the project.
- A database or app in the same project.
Connect a resource
Section titled “Connect a resource”- Open the app.
- Go to Variables.
- Select Use a resource.
- Select a database or app.
- Select Save.
For a database, Orchard adds the variable DATABASE_URL if the name is free. For an app, Orchard adds a variable named <NAME>_URL.
To read a different field, select the reference in the variable row, then select the field. To replace the reference with text, select Type a value instead.
To connect a database and add DATABASE_URL, run the following command:
orchard deploy bindings add <id> --database <name>To connect an app, run the following command:
orchard deploy bindings add <id> --app <name>| Flag | Description |
|---|---|
--as | The connection name used in the reference. The default comes from the resource name. |
--env | The variable to add. |
--no-env | Connect the resource without adding a variable. |
To list the resources that you can connect, run the following command:
orchard deploy bindings options <id>Available fields
Section titled “Available fields”| Resource | Field | Value |
|---|---|---|
| Database | connection_string | The full Postgres connection string. This value is secret. |
| Database | host | The database host. |
| Database | port | The database port. |
| Database | database | The database name. |
| Database | user | The database user. |
| Database | password | The database password. This value is secret. |
| App | url | The internal URL of the app, in the format http://<host>:<port>. |
| App | host | The internal hostname of the app. |
| App | port | The port of the app’s first service. |
App fields come from the app’s first service. An app with no service has no fields.
Limits
Section titled “Limits”- An app can connect to 20 resources.
- A connection name starts with a lowercase letter. It contains only lowercase letters, digits, and underscores. It has 32 characters at most.
Remove a connection
Section titled “Remove a connection”- Open the app.
- Go to Variables.
- Remove all variables that use the connection.
- Select Save.
Orchard removes a connection when no variable uses it.
Remove all variables that use the connection, then run the following command:
orchard deploy bindings remove <id> <name>You cannot delete a database while an app is connected to it.
Unresolved references
Section titled “Unresolved references”If a variable refers to a connection or field that does not exist, the app does not start. Orchard does not pass an empty value to the app.
Related resources
Section titled “Related resources”- Create and manage a database - Create the Postgres database an app connects to.
- score.yaml - Declare database connections in a file in the repository.
orchard deploy bindingsreference - Every flag of theorchard deploy bindingscommands.