App Platform is a Platform-as-a-Service (PaaS) offering that allows developers to publish code directly to DigitalOcean servers without worrying about the underlying infrastructure.
You can add a dev database or an existing DigitalOcean Manged Database to your app at any time. Dev databases only support PostgreSQL at this time.
Dev databases are located in the same region as your app and cannot be migrated to another region. If you migrate your app to a different region, the app won’t be able to access the associated dev database anymore. If you need to migrate your app and dev database, we recommend either backing up the contents of the database and restoring it after the app’s migration, or using a DigitalOcean Managed Database instead. You can migrate managed databases independently of apps to different regions as needed.
You can create a database during your app’s initial creation or add one later using the DigitalOcean Control Panel. You can also add a database to an app by defining it in your app’s spec file and then submitting the new spec using either the API, CLI, DigitalOcean Control Panel, or the app’s source repo.
This section focuses on adding a database to an existing app using various methods.
You can add a database to an app using the CLI’s app update command or the API’s app update endpoint. To add a database, update the app’s spec with the database’s specifications and submit the spec using the following command or endpoint.
In the Apps section of the DigitalOcean Control Panel, click your app, then click the Create dropdown. Add a database resource by choosing the Create/Attach Database option.
Select your database configuration, choosing from the available engines and plans. You can add a dev database or an existing managed database from your DigitalOcean account.
All DigitalOcean database clusters support apps as trusted sources. Your app is added as a trusted source to the dev database. This creates a secure connection to the database and it accepts traffic only from the app. Similarly, if your existing managed database has trusted sources enabled, the app is automatically added as a trusted source. If trusted source is disabled for your managed database, select the Add app as a trusted source option to add the app as a trusted source.
Alternatively, you can specify an app in the Trusted sources section in the Settings tab of the database in the cloud control panel. This starts an app redeployment that enables a connection restricted from that app to the database.
When you are ready to proceed, click Create and Attach to confirm your choices.
You can also add a database by specifying the database details directly in the app’s spec file and submitting the updated spec via the control panel or uploading it to your app’s source repo.
To add a database using the app’s spec, add the following object to root of the spec and update the values as necessary:
databases:
- engine: PG
name: db-example
version: "16"
Using the spec, you can specify the database’s name and version. You cannot specify the version the control panel. The currently available PostgreSQL versions are 14
and 16
.
Go to control panel, click on your app, and click on the Settings tab.
Click on your database to view its details. The connection information for your database is provided in the Connection Details section.
The full connection string for your database is also be available as a runtime environment variable named DATABASE_URL
which you can use in your application code. You should see this it in the details for your service resource, set to a value such as:
postgres://${db.USERNAME}:${db.PASSWORD}@${db.HOSTNAME}:${db.PORT}/${db.DATABASE}
DATABASE_URL
wraps several environment variables that you can also access individually, such as db.USERNAME
, db.PASSWORD
, and so on.
You can upgrade your dev database to a DigitalOcean Managed Database at any time. When you upgrade your database, we migrate the existing data to a new managed database.
To upgrade your dev database, go to the control panel, click on your app, and click on the Settings tab.
Click the dev database you would like to upgrade to a managed database and click the Upgrade to a Managed Database button. You can choose the size of the machines that run your database with the Node Plan drop-down, and add standby nodes that stay synchronized and provide failover during downtime with the Standby Nodes drop-down.
Click Upgrade Database to complete the process.
You can create and integrate DigitalOcean Managed Kafka Databases with your App Platform app, but they require an additional step to configure the app’s ability to connect to the database.
App Platform does not currently support connections to Kafka databases that have trusted sources enabled. You must disable trusted sources on the Kafka database before it can be integrated with an App Platform app.
App Platform provides bindable environment variables that automatically provide connection details for your Kafka database. To integrate an existing Kafka database, follow the steps to add the database to your app, then add the following environment variable key value pairs to your app, replacing your-kafka-instance-name
with your database cluster’s name:
Example Key | Value Format | Description |
---|---|---|
KAFKA_BROKER | ${your-kafka-instance-name.HOSTNAME}:${your-kafka-instance-name.PORT} | The hostname and port of the database’s Kafka brokers |
KAFKA_USERNAME | ${your-kafka-instance-name.USERNAME} | The username for authenticating with the Kafka database |
KAFKA_PASSWORD | ${your-kafka-instance-name.PASSWORD} | The password for authenticating with the Kafka database |
KAFKA_CA_CERT | ${your-kafka-instance-name.CA_CERT} | The CA certificate for TLS authentication with the Kafka database |
You can pass these environment variables to the Kafka client in your app’s code to securely connect to the client.
App Platform does not support connecting to managed databases with trusted sources enabled during the app’s build process. To allow your app to connect to the database during development, you need to disable trusted sources on the database.
Go to the control panel, click on your app, and click on the Settings tab.
Click on your database to view its details. The trusted sources information for your database is provided in the Trusted Sources section. To disable the setting, click Edit, uncheck the Add app as a trusted source checkbox, and click Save.
Go to the control panel, click on your app, and click on the Settings tab.
Click on your database. The details screen for your database has a Destroy Database button on the bottom that will destroy your database after you confirm the action.