Skip to content

Drizzle Postgres on Prisma Compute

Prisma here means Alchemy’s Prisma hosting and database provider, not Prisma ORM. Complete Prisma setup, start from the prisma-compute-effect example, and add a src/schema.ts exporting Users from the Postgres client guide.

Terminal window
pnpm add drizzle-orm@1.0.0-rc.5-ab785fc @effect/sql-pg pg
pnpm add -D drizzle-kit@1.0.0-rc.5-ab785fc

The Drizzle versions match the repository’s Effect integration.

drizzle.config.ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: "postgresql",
schema: "./src/schema.ts",
out: "./drizzle",
dbCredentials: { url: process.env.DATABASE_URL! },
});

The migration runner needs the direct Postgres connection URL, not an Accelerate URL.

Terminal window
pnpm exec drizzle-kit generate

Review the generated SQL and snapshots, including any rename decisions, before applying them.

Terminal window
git add src/schema.ts drizzle.config.ts drizzle
git diff --cached
Terminal window
git commit -m "Add users migration"

Commit the schema, SQL, and snapshots together; deployment consumes this reviewed history.

The starter’s src/Database.ts creates an explicit Prisma Postgres database rather than relying on the project’s default database:

export const Postgres = Prisma.Postgres(
"Postgres",
Effect.gen(function* () {
const project = yield* Project;
return { project, region, branchGitName: "main" };
}),
);

Keep createDatabase: false on Project, and use the same project and branch for Compute.

export const Connection = Prisma.Connection(
"Connection",
Effect.gen(function* () {
const postgres = yield* Postgres;
return { database: postgres, name: "api" };
}),
);

This is the starter’s connection resource; its redacted outputs include direct and pooled URLs when available.

// Inside the runtime Effect in src/Api.ts
const db = yield* Prisma.Connect(Connection);
// On that runtime Effect
.pipe(Effect.provide(Prisma.ConnectBinding))

Prisma.Compute<Api>() uses main: import.meta.filename and binds connection values into its environment. db.databaseUrl is the connection Effect to pass to Drizzle, not a SQL execution method.

Terminal window
pnpm alchemy deploy

Keep the starter’s Prisma.providers(), yield* Api, and /api/health handler for this initial deployment. Its connection-binding check does not query application tables.

Terminal window
pnpm exec drizzle-kit migrate

Supply the connection resource’s directConnectionString output as the migration runner’s secret DATABASE_URL; it must contain a PostgreSQL URL, not be absent or Accelerate-only. Prisma.Postgres has no production migrations prop, and dev.migrate only runs against the local development database.

src/Api.ts
import * as Drizzle from "alchemy/Drizzle/Postgres";
const db = yield* Prisma.Connect(Connection);
const database = yield* Drizzle.Postgres(db.databaseUrl);

databaseUrl prefers pooled Postgres and then direct Postgres; use a connection that actually has one of those URLs, since Drizzle’s pg driver cannot use an Accelerate-only fallback.

Import Users from ./schema.ts and replace the starter’s fetch handler:

fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
const path = new URL(request.url, "http://localhost").pathname;
if (path === "/api/health") {
return yield* HttpServerResponse.json({ ok: true });
}
const users = yield* database.select().from(Users).pipe(Effect.orDie);
return yield* HttpServerResponse.json({ users });
}),

Keep the existing healthCheck: { path: "/api/health" }; application queries now run within the request scope.

Terminal window
pnpm alchemy deploy
curl "$API_URL/"

Set API_URL to the Stack’s url output and verify the query response, not just /api/health. For later changes, generate, review, and commit first, then apply migrations and deploy compatible code; alchemy deploy does not replace drizzle-kit migrate.

See the Prisma Postgres guide, Compute deployment guide, portable Postgres queries, and migration workflow. The Prisma tutorial example exercises the same Postgres driver through SQL.Postgres in Compute.