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.
Install the database dependencies
Section titled “Install the database dependencies”pnpm add drizzle-orm@1.0.0-rc.5-ab785fc @effect/sql-pg pgpnpm add -D drizzle-kit@1.0.0-rc.5-ab785fcThe Drizzle versions match the repository’s Effect integration.
Configure migrations
Section titled “Configure migrations”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.
Generate after changing the schema
Section titled “Generate after changing the schema”pnpm exec drizzle-kit generateReview the generated SQL and snapshots, including any rename decisions, before applying them.
Commit the migration
Section titled “Commit the migration”git add src/schema.ts drizzle.config.ts drizzlegit diff --cachedgit commit -m "Add users migration"Commit the schema, SQL, and snapshots together; deployment consumes this reviewed history.
Keep the standalone database
Section titled “Keep the standalone database”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.
Keep the connection resource
Section titled “Keep the connection resource”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.
Keep the Compute binding
Section titled “Keep the Compute binding”// Inside the runtime Effect in src/Api.tsconst 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.
Provision before the first migration
Section titled “Provision before the first migration”pnpm alchemy deployKeep the starter’s Prisma.providers(), yield* Api, and /api/health handler for this initial deployment. Its connection-binding check does not query application tables.
Apply the committed SQL
Section titled “Apply the committed SQL”pnpm exec drizzle-kit migrateSupply 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.
Open the Drizzle client
Section titled “Open the Drizzle client”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.
Query from Compute
Section titled “Query from Compute”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.
Deploy and exercise the query
Section titled “Deploy and exercise the query”pnpm alchemy deploycurl "$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.
Continue
Section titled “Continue”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.