Drizzle ORM with Neon
Use the portable Drizzle Postgres client with Neon; this page configures the database and its connections. For Worker deployment, follow Add Drizzle ORM.
Configure migration generation
Section titled “Configure migration generation”import { defineConfig } from "drizzle-kit";
export default defineConfig({ schema: "./src/schema.ts", out: "./migrations", dialect: "postgresql",});Use a pg-core schema as shown in Drizzle Postgres; generation does not need Neon credentials.
Generate and review migrations
Section titled “Generate and review migrations”bunx drizzle-kit generategit diff -- src/schema.ts migrationsgit status --shortgit add src/schema.ts drizzle.config.ts migrationsgit diff --cachedgit commit -m "Add database migration"Run this when the schema changes, then review and commit the schema, generated SQL, and snapshots together before deploying. The optional Drizzle.Schema resource is a separate integration, not required for this workflow.
Feed migrations from the schema
Section titled “Feed migrations from the schema”import * as Neon from "alchemy/Neon";import * as Effect from "effect/Effect";
export const NeonDb = Effect.gen(function* () { const project = yield* Neon.Project("app-db", { region: "aws-us-east-1", }); const branch = yield* Neon.Branch("app-branch", { project, migrations: "./migrations", }); return { project, branch };});With Neon.providers() registered in your Stack, Neon.Branch applies the committed directory; Neon.Project accepts the same prop for its default branch. Neon migrations covers transaction and tracking behavior.
Iterate
Section titled “Iterate”bun alchemy deployDeploy the committed files; this configuration does not generate SQL during deployment. If you already use drizzle-kit migrate, keep that application workflow unless you deliberately choose Alchemy-managed migrations; see migration ownership.
Connect at runtime
Section titled “Connect at runtime”import * as Cloudflare from "alchemy/Cloudflare";
export const Hyperdrive = Effect.gen(function* () { const { branch } = yield* NeonDb; return yield* Cloudflare.Hyperdrive.Connection("app-hyperdrive", { origin: branch.origin, dev: branch.pooledOrigin, });});Use branch.origin when Hyperdrive handles pooling, and branch.pooledOrigin for local development that bypasses Hyperdrive. Other runtimes can use connectionUri or pooledConnectionUri; Connections covers their configuration, and the Cloudflare walkthrough owns Worker bindings and queries.
Where next
Section titled “Where next”Read Preview branches per PR for branch provisioning, or SQL databases for client discovery. The Project and Branch references cover resource options.