> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# DigitalOcean Databases

> Managed Postgres, MySQL, MongoDB, Valkey, Kafka, and OpenSearch.

## What is this integration?

Provision and manage DigitalOcean managed databases.

## Supported Engines

| Engine       | Slug         | Versions               |
| ------------ | ------------ | ---------------------- |
| PostgreSQL   | `pg`         | 11, 12, 13, 14, 15, 16 |
| MySQL        | `mysql`      | 5.7, 8.0               |
| Valkey       | `valkey`     | 7, 8                   |
| MongoDB      | `mongodb`    | 4.4, 5.0, 6.0, 7.0     |
| Apache Kafka | `kafka`      | 3.5                    |
| OpenSearch   | `opensearch` | 1.x, 2.x               |

> **Note:** Redis has been replaced by Valkey on DigitalOcean. If you want to use Redis, use `valkey` as the engine instead. For backwards compatibility, specifying `engine: redis` will automatically be mapped to `valkey`.

## What Monk manages

* Database clusters and configuration

## Obtaining DigitalOcean Credentials

To use DigitalOcean Managed Databases with Monk, you'll need a DigitalOcean API token.

### What You'll Need

* **Personal Access Token** - DigitalOcean API token with read/write access
* **Optional:** Default region (e.g., `nyc1`)

### Step-by-Step

1. **Log into DigitalOcean** at [https://cloud.digitalocean.com](https://cloud.digitalocean.com)
2. Click **API** in the left sidebar
3. Go to **Tokens/Keys** tab
4. Click **Generate New Token**
5. **Token name:** "Monk Deployment"
6. **Scopes:** Check both **Read** and **Write**
7. Click **Generate Token**
8. **Copy the token immediately** - it's shown only once
9. Save it securely

### Providing to Monk

When deploying to DigitalOcean, ask Monk:

```
deploy to DigitalOcean
```

```
use DigitalOcean managed MongoDB
```

Monk will request your DigitalOcean credentials if not already configured.

### Security Best Practices

✅ **Rotate tokens regularly** - Generate new tokens every 90 days
✅ **Revoke unused tokens** - Remove old tokens from DigitalOcean
✅ **Use minimal scopes** - Read + Write is sufficient for Monk
✅ **Monitor usage** - Check DigitalOcean activity logs

## Getting Started

1. Provide DigitalOcean credentials to Monk when prompted

2. Define a PostgreSQL cluster (save as do-db.yaml):

```yaml theme={null}
namespace: digitalocean-database-example

my-postgres-db:
  defines: digitalocean-database/database
  name: my-postgres-cluster
  engine: pg
  version: "16"
  num_nodes: 1
  region: nyc1
  size: db-s-1vcpu-1gb
```

3. Create/update:

```bash theme={null}
monk update digitalocean-database-example/my-postgres-db
```

## Backup & Restore Actions

DigitalOcean managed databases include automatic daily backups with 7-day retention.

| Action               | Description                        | Key Parameters                          |
| -------------------- | ---------------------------------- | --------------------------------------- |
| `get-backup-info`    | Show backup config and PITR status | -                                       |
| `list-backups`       | List available backup points       | -                                       |
| `describe-backup`    | Get backup details                 | `backup_created_at`                     |
| `restore`            | Fork new cluster from backup       | `new_cluster_name`, `backup_created_at` |
| `get-restore-status` | Check fork progress                | `cluster_id`                            |

### Restore Example

```bash theme={null}
# List available backups
monk do digitalocean-database-example/my-postgres-db/list-backups

# Restore to new cluster
monk do digitalocean-database-example/my-postgres-db/restore \
  --new_cluster_name=restored-db \
  --backup_created_at=2024-01-15T00:00:00Z
```

**Note:** Restore creates a NEW independent cluster (no in-place restore). PITR is supported for PostgreSQL and MySQL only.

## Composing with Other Entities

Use `connection-target` to wire your app to a DigitalOcean managed database and read connection details from its state:

```yaml theme={null}
namespace: my-infra

my-postgres-db:
  defines: digitalocean-database/database
  name: my-app-db
  engine: pg
  version: "16"
  num_nodes: 1
  region: nyc1
  size: db-s-1vcpu-1gb

my-app:
  defines: runnable
  variables:
    db-host:
      type: string
      value: <- connection-target("database") entity-state get-member("connection_host")
      env: DB_HOST
    db-port:
      type: string
      value: <- connection-target("database") entity-state get-member("connection_port")
      env: DB_PORT
    db-user:
      type: string
      value: <- connection-target("database") entity-state get-member("connection_user")
      env: DB_USER
    db-password:
      type: string
      value: <- connection-target("database") entity-state get-member("connection_password")
      env: DB_PASSWORD
    db-name:
      type: string
      value: <- connection-target("database") entity-state get-member("connection_database")
      env: DB_NAME
  connections:
    database:
      runnable: my-infra/my-postgres-db
      service: data
  depends:
    wait-for:
      runnables:
        - my-infra/my-postgres-db
      timeout: 120
```
