Skip to content

DigitalOcean.Databases reference

Source: packages/digitalocean/src/Databases/Cluster.ts

A DigitalOcean Managed Database cluster: PostgreSQL, MySQL, Valkey, MongoDB, Kafka or OpenSearch. Size, node count, storage, region, a higher version, tags and the maintenance window update in place; name, engine, vpcUuid and a lower version replace the cluster, which loses its data.

Alchemy tags every cluster it creates with an alchemy: ownership tag and an alchemy:generation: tag, so an interrupted deploy resumes on the cluster it already created. A same-named cluster without the ownership tag is Unowned and needs --adopt.

A cluster takes five to ten minutes to come online; reconcile returns once it is online.

A single-node PostgreSQL cluster

const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
version: "17",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
// pg.uri is a Redacted postgresql:// URI for the doadmin user.

A high-availability MySQL cluster in a VPC

const network = yield* DigitalOcean.Vpc("network", { region: "nyc3" });
const mysql = yield* DigitalOcean.Databases.Cluster("mysql", {
engine: "mysql",
size: "db-s-2vcpu-4gb",
numNodes: 3,
region: "nyc3",
vpcUuid: network.vpcId,
maintenanceWindow: { day: "sunday", hour: "03:00" },
});
const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
const app = yield* DigitalOcean.Databases.Database("app", {
clusterId: pg.clusterId,
migrations: "./migrations",
});
const user = yield* DigitalOcean.Databases.User("app-user", { clusterId: pg.clusterId });
yield* DigitalOcean.Databases.ConnectionPool("app-pool", {
clusterId: pg.clusterId,
database: app.name,
user: user.name,
size: 10,
});
const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
const host = yield* DigitalOcean.Droplet("app", {
region: "nyc3",
size: "s-1vcpu-1gb",
image: "ubuntu-24-04-x64",
});
yield* DigitalOcean.Databases.Firewall("db-firewall", {
clusterId: pg.clusterId,
rules: [{ type: "droplet", value: String(host.dropletId) }],
});

Source: packages/digitalocean/src/Databases/Connect.ts

Connect a runtime to a Managed Database cluster or a connection pool. The connection URIs reach the host as secrets in its environment, so this works from a DigitalOcean.App and from any other cloud’s runtime. Pass a ConnectionPool to go through PgBouncer.

const Db = DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const conn = yield* DigitalOcean.Databases.Connect(Db);
const db = yield* Drizzle.Postgres(conn.connectionString);
return {
fetch: Effect.gen(function* () {
const rows = yield* db.select().from(users);
return yield* HttpServerResponse.json(rows);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Databases.ConnectHttp)),
) {}

Source: packages/digitalocean/src/Databases/ConnectHttp.ts Kind: Layer · Provides: DigitalOcean.Databases.Connect

Connect for any host: the connection URIs travel as secrets through the host’s runtime context.

Source: packages/digitalocean/src/Databases/ConnectionPool.ts

A PgBouncer connection pool on a PostgreSQL Managed Database cluster. Runtimes that open many short connections (functions, serverless apps) connect to the pool instead of the database. Everything but the name and cluster updates in place.

const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
const app = yield* DigitalOcean.Databases.Database("app", { clusterId: pg.clusterId });
const pool = yield* DigitalOcean.Databases.ConnectionPool("app-pool", {
clusterId: pg.clusterId,
database: app.name,
size: 10,
});
// Connect to pool.uri.

Source: packages/digitalocean/src/Databases/Database.ts

A database in a PostgreSQL or MySQL Managed Database cluster, with schema migrations applied on every deploy.

const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
const app = yield* DigitalOcean.Databases.Database("app", { clusterId: pg.clusterId });

Apply a directory of migrations on deploy

const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
const app = yield* DigitalOcean.Databases.Database("app", {
clusterId: pg.clusterId,
migrations: "./migrations",
});

A MySQL database with its own bookkeeping table

const mysql = yield* DigitalOcean.Databases.Cluster("mysql", {
engine: "mysql",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
yield* DigitalOcean.Databases.Database("shop", {
clusterId: mysql.clusterId,
migrations: { dir: "./migrations", table: "schema_history" },
});

Source: packages/digitalocean/src/Databases/Firewall.ts

The trusted sources of a Managed Database cluster: only these droplets, tags, Kubernetes clusters, apps and addresses may connect. The rules are replaced as a whole on every change. Destroying the resource removes the restriction, so any source may connect again.

Deploys that apply Database migrations connect from the deploying machine, so include its address while migrations run.

const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
const host = yield* DigitalOcean.Droplet("app", {
region: "nyc3",
size: "s-1vcpu-1gb",
image: "ubuntu-24-04-x64",
});
yield* DigitalOcean.Databases.Firewall("db-firewall", {
clusterId: pg.clusterId,
rules: [
{ type: "droplet", value: String(host.dropletId) },
{ type: "ip_addr", value: "203.0.113.0/24" },
],
});

Source: packages/digitalocean/src/Databases/Replica.ts

A read-only replica of a PostgreSQL or MySQL Managed Database cluster, in the cluster’s region or another one. Point read-heavy work at replica.uri. Every prop replaces the replica.

const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-2gb",
region: "nyc3",
});
const reads = yield* DigitalOcean.Databases.Replica("db-reads", {
clusterId: pg.clusterId,
size: "db-s-1vcpu-2gb",
region: "sfo3",
});

Source: packages/digitalocean/src/Databases/User.ts

A user in a Managed Database cluster, with a password DigitalOcean generates. Pass user.password to a runtime as a secret.

const pg = yield* DigitalOcean.Databases.Cluster("db", {
engine: "pg",
size: "db-s-1vcpu-1gb",
region: "nyc3",
});
const user = yield* DigitalOcean.Databases.User("app-user", { clusterId: pg.clusterId });
// Connect as user.name with user.password to pg.host:pg.port.