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 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 for your app using the DigitalOcean Control Panel or by defining the database 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.
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 https://cloud.digitalocean.com/apps, 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.
Go to https://cloud.digitalocean.com/apps, 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.
Go to https://cloud.digitalocean.com/apps, 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 https://cloud.digitalocean.com/apps, 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.