Skip to content

feat: add Prisma provider - #416

Merged
sam-goodwin merged 135 commits into
alchemy-run:mainfrom
AmanVarshney01:aman/prisma-alchemy-provider
Jul 29, 2026
Merged

sam-goodwin merged 135 commits into
alchemy-run:mainfrom
AmanVarshney01:aman/prisma-alchemy-provider

Conversation

@AmanVarshney01

@AmanVarshney01 AmanVarshney01 commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Production-grade Prisma provider for Alchemy: declarative resources for Prisma Postgres and Prisma Compute, aligned with the current Prisma Management API, covering framework applications and Effect-native services. Resources reconcile from observed API state, recover from interrupted deployments, and never persist Prisma credentials as plaintext.

Quick start

import * as Alchemy from "alchemy";
import * as Cloudflare from "alchemy/Cloudflare";
import * as Prisma from "alchemy/Prisma";
import * as Effect from "effect/Effect";

export default Alchemy.Stack(
  "PrismaApp",
  { providers: Prisma.providers(), state: Cloudflare.state() },
  Effect.gen(function* () {
    const project = yield* Prisma.Project("Project", { createDatabase: false });
    const postgres = yield* Prisma.Postgres("Postgres", { project });
    const connection = yield* Prisma.Connection("Connection", {
      database: postgres,
    });

    const app = yield* Prisma.Compute("App", {
      project,
      path: "./app",
      build: {
        command: "bun run build",
        outdir: ".output",
        entrypoint: "server/index.mjs",
      },
      port: 3000,
      healthCheck: { path: "/api/health" },
      env: { DATABASE_URL: connection.databaseUrl },
      destroyOldDeployment: true,
    });

    return { url: app.url };
  }),
);

Names (Project.name, Database.name, Connection.name, Branch.gitName, App.displayName, Compute.appName) are optional — omitted, alchemy generates stable physical names via PhysicalName.

Provider surface

API Purpose
Project Creates and manages a Prisma project
Database / Postgres Manages Prisma Postgres databases
Branch Manages database branches
Connection Named database credentials with typed, redacted outputs
Connect / ConnectBinding Runtime binding for Compute, Lambda, and Workers
App / Deployment / Compute Builds, uploads, deploys, promotes, verifies, and replaces applications
EnvironmentVariable, CustomDomain, SourceRepository Compute app configuration

Plus Management API operation helpers, deployment log tailing, and bun nuke coverage (--include 'Prisma.*').

Connections

A Connection materializes ready-to-use outputs — all secrets Redacted:

connection.databaseUrl; //            pooled → direct → Accelerate
connection.directConnectionString; // for migration tooling
connection.origin; //                 parsed PostgresOrigin components
connection.pooledOrigin;

origin feeds straight into Cloudflare Hyperdrive, the same shape Neon branches and PlanetScale roles materialize:

const hyperdrive = yield* Cloudflare.Hyperdrive.Connection("api-hd", {
  origin: connection.origin.as<Prisma.PostgresOrigin>(),
});

Covered by a live test that deploys a Worker querying Prisma Postgres through Hyperdrive with SQL.Postgres.

Runtime binding

Prisma.Connect resolves a bound connection inside a Compute app, Lambda function, or Cloudflare Worker — db.databaseUrl plugs directly into SQL.Postgres / Drizzle:

export default Prisma.Compute(
  "Api",
  { project, main: import.meta.filename },
  Effect.gen(function* () {
    const db = yield* Prisma.Connect(connection);
    const sql = yield* SQL.Postgres({ url: db.databaseUrl });

    return {
      fetch: Effect.gen(function* () {
        const users = yield* sql`SELECT * FROM users`;
        return yield* HttpServerResponse.json(users);
      }),
    };
  }).pipe(Effect.provide(Prisma.ConnectBinding)),
);

Deployment lifecycle

A Compute update is fail-closed: build → upload (bounded, streamed I/O) → start candidate → verify preview health → promote → confirm latest → verify stable endpoint → only then stop/destroy the previous deployment. Failed or ambiguous operations preserve the last healthy deployment; terminally failed deployments are never restarted or chosen as rollback targets.

Hardening includes observed-state reconciliation with explicit adoption, idempotent lifecycle paths, bounded retries and subprocess timeouts, process-group termination of timed-out builds, path-traversal/symlink/artifact-mutation checks, and redaction of connection strings and service tokens from state, logs, errors, and subprocess output. Ambient Prisma credentials are withheld from build and migration subprocesses.

Local development

bun alchemy dev runs the whole stack against a local @prisma/dev Postgres with zero credentials; dev.migrate on the database and dev.command on Compute wire up migrations and the local app.

Management API compatibility

Synchronized with the current prisma/pdp-control-plane Management API: canonical /v1/apps and /v1/deployments routes, all 71 canonical provider routes covered, the contract pinned to the current 102 public operations (24 deprecated aliases and 7 Object Storage routes explicitly deferred), API state as the source of truth during reconciliation.

Docs

Dedicated provider hub at /prisma (overview, setup, Postgres, connections, Compute, and a Workers guide), wired into the docs tabs and sidebar like PlanetScale and Neon.

Examples

@AmanVarshney01 AmanVarshney01 changed the title Experimental Prisma provider cleanup Experimental Prisma provider for Alchemy May 22, 2026
@AmanVarshney01
AmanVarshney01 force-pushed the aman/prisma-alchemy-provider branch 3 times, most recently from 86a9960 to f2087fb Compare May 22, 2026 11:45
@sam-goodwin

Copy link
Copy Markdown
Member

Are you planning on adding an effect-native ComputeApp Platform and Bindings? One that works like Cloudflare Workers or Lambda Function?

https://v2.alchemy.run/concepts/platform/

@AmanVarshney01
AmanVarshney01 force-pushed the aman/prisma-alchemy-provider branch from f2087fb to c3af6c7 Compare May 26, 2026 06:50
@AmanVarshney01

Copy link
Copy Markdown
Contributor Author

Are you planning on adding an effect-native ComputeApp Platform and Bindings? One that works like Cloudflare Workers or Lambda Function?

https://v2.alchemy.run/concepts/platform/

Interesting didn’t know about this. I’ll get back to you on this in a bit.

@AmanVarshney01
AmanVarshney01 force-pushed the aman/prisma-alchemy-provider branch from c3af6c7 to 0952b7a Compare May 26, 2026 06:56
@AmanVarshney01
AmanVarshney01 marked this pull request as ready for review June 16, 2026 12:25
AmanVarshney01 and others added 6 commits June 23, 2026 04:05
…rovider

# Conflicts:
#	.oxfmtrc.json
#	bun.lock
#	packages/alchemy/package.json
…PI surface

- rework ConnectionBinding to the single binding convention (alchemy-run#690): combined
  tag/callable + Binding.Host dispatch inside ConnectionBindingLive, drop
  Binding.Policy machinery and its Providers registrations
- replace the removed Build/Command helper (alchemy-run#673) with a local spawner-based
  runBuildCommand in ComputeBuild
- update shape-typed class forms to the id-only + .make(props, impl) Platform API
- add the /v1/apps, /v1/deployments, and build-logs surface to the client,
  operation helpers, and route-parity tests (96-route coverage)
- add ScmInstallation.connected/connectedAt, the connected list filter, and
  connectScmInstallation for the new SCM connect endpoint; unreleased routes
  are allowlisted until they ship to the production OpenAPI doc
@AmanVarshney01 AmanVarshney01 changed the title feat: prisma provider feat(prisma): add production management api provider Jul 10, 2026
@AmanVarshney01 AmanVarshney01 changed the title feat(prisma): add production management api provider feat: add Prisma provider Jul 10, 2026
AmanVarshney01 and others added 9 commits July 23, 2026 17:36
…rep-5ba5cc

# Conflicts:
#	bun.lock
#	packages/alchemy/src/Plan.ts
…ehavior

- run codemod-alchemy-test over the Prisma (and Command executor) suites
- enforce the 1 MiB deployment-log frame limit in parseDeploymentLogRecord:
  bun's ws shim ignores the socket maxPayload option, so the socket-level
  bound alone no longer rejects oversized frames
- route the managementApi() Providers test down the env-credential path
  (CI: true) instead of consulting the machine's profile store
- make withWebSocketServer's release bounded: bun's ws shim can never fire
  the server.close callback after a server-initiated client close, which
  hung the uninterruptible finalizer and the whole test process

Co-Authored-By: Claude Fable 5 <[email protected]>
- Prisma.ConnectionBinding/ConnectionBindingLive -> Prisma.Connect/ConnectBinding
  (mirrors Cloudflare.Hyperdrive.Connect + ConnectBinding), moved to Connect.ts
- drop connectionUrl()/connectionEnv() helpers; the Connection resource now
  materializes databaseUrl (pooled -> direct -> accelerate) plus parsed
  origin/pooledOrigin PostgresOrigin attrs, like Planetscale roles and Neon
  branches, so Hyperdrive wiring is origin-shaped:
    Cloudflare.Hyperdrive.Connection("hd", { origin: connection.origin.as<Prisma.PostgresOrigin>() })
- ConnectClient now returns Redacted connection strings; databaseUrl feeds
  SQL.Postgres({ url: db.databaseUrl }) / Drizzle directly
- live Prisma-over-Hyperdrive Worker test + lean fixture (deep imports keep
  pglite out of the Worker bundle)
- retry Cloudflare script PUTs on pure transport failures (idempotent upsert)

Co-Authored-By: Claude Fable 5 <[email protected]>
…tack

Prisma.providers() provideMerge'd NodeHttpClient.layerNodeHttp, overriding
the ambient HttpClient for every provider in a merged stack. Cloudflare
Worker script uploads then went out over node:http, which streams multipart
bodies as Transfer-Encoding: chunked — api.cloudflare.com never answers
chunked uploads, so any stack combining Prisma + Cloudflare providers hung
on every Worker deploy.

- provide (not provideMerge) the node transport to the Prisma management
  client only
- artifact uploads get a Prisma-scoped PrismaUploadClient service (node
  transport, needed for Content-Length on presigned URLs); tests that stub
  the ambient HttpClient fall back to it unchanged
- retry Cloudflare script PUTs on pure transport failures (idempotent
  upsert)

Verified live: Prisma Postgres -> Hyperdrive -> Worker SQL round trip with
full create/destroy lifecycle, plus the Compute live suite.

Co-Authored-By: Claude Fable 5 <[email protected]>
The PR branch's earlier merges of main resolved conflicts by keeping
pre-merge versions — silently deleting whole features main had since
landed (src/Telemetry.ts, Axiom Telemetry, Docker Swarm/Service/Context
and their tests, three docs pages) and rewinding ~50 more files (worker
bridges, compat flags, tutorials, astro config).

Restored every file that diverges from origin/main and was never touched
by a non-merge commit on this branch, keeping the PR's intentional
changes (Plan/Apply/Http/Command/State + Prisma) and this prep branch's
fixes. bun tsc -b clean.

Co-Authored-By: Claude Fable 5 <[email protected]>
…rep-5ba5cc

# Conflicts:
#	packages/alchemy/test/Cloudflare/Website/StaticSite.test.ts
#	packages/alchemy/test/Cloudflare/Workers/Worker.test.ts
#	website/src/content/docs/cloudflare/tutorial/part-6.mdx
#	website/src/content/docs/docker/swarm.mdx
Adds Prisma.providers() to the nuke stack so `bun nuke` (and
`--include 'Prisma.*'`) covers Prisma projects/databases/connections.
Requires PRISMA_SERVICE_TOKEN (with CI=1) or a configured profile, same
as Neon/Planetscale.

Verified: nuked 88 leaked distilled-prisma-* test projects, ran the full
Prisma suite (351 passed incl. live Compute + Hyperdrive), and the
post-suite census is empty — tests leave the account clean.

Co-Authored-By: Claude Fable 5 <[email protected]>
Adds the Prisma hub alongside PlanetScale and Neon:

- /prisma — overview (resources, Connect binding, the Prisma path)
- /prisma/setup — service tokens, login methods, CI
- /prisma/data/postgres — Project/Postgres/Branch + @prisma/dev local dev
- /prisma/data/connections — databaseUrl, connection strings, origins,
  Connect binding, rotation
- /prisma/compute — framework + Effect-native apps, health-checked
  promotion, custom domains, dev command
- /prisma/guides/cloudflare-workers — Hyperdrive vs Connect wiring

Wires the sidebar hub, primary docs tab, Reference list entry, and the
Prisma brand icon.

Co-Authored-By: Claude Fable 5 <[email protected]>
@sam-goodwin sam-goodwin added the deploy-website Deploy the website preview for this PR label Jul 29, 2026
sam-goodwin and others added 3 commits July 28, 2026 18:50
Connection.name, Branch.gitName, App.displayName, and Compute.appName are
now optional. When omitted:

- Branch/App/Compute derive a stable physical name via createPhysicalName
  (stack-id-stage + instance suffix), like Project and Database already did
- Connection defaults its name prefix to the logical ID; its existing
  scheme appends the instance identity, so omitted names recover and adopt
  exactly like explicit ones

Defaults resolve identically across diff/read/reconcile so an omitted name
never reads as drift, and dev providers mirror the same shape. Docs and
examples now omit names by default.

Co-Authored-By: Claude Fable 5 <[email protected]>
…rep-5ba5cc

# Conflicts:
#	packages/alchemy/src/Command/Dev.ts
Sidebar now mirrors the Neon hub shape:

  Data     { Postgres, Branches, Connections }
  Compute  { Apps, Deployments }
  Guides   { Connect from Workers }

- new /prisma/data/branches — attachment, branch-per-stage, default
  promotion and its restore-on-destroy behavior
- /prisma/compute split into /prisma/compute/apps (builds, Effect-native,
  custom domains, dev) and /prisma/compute/deployments (health-checked
  promotion, rollback, destroyOldDeployment, skipCodeUpload, no-op
  convergence)

Co-Authored-By: Claude Fable 5 <[email protected]>
@sam-goodwin
sam-goodwin merged commit 92f9b3a into alchemy-run:main Jul 29, 2026
8 checks passed
john-royal added a commit that referenced this pull request Jul 30, 2026
Brings in 94 commits from main (local vs live provider modes #963,
workersDev/domain props #977, Worker.URL self-binding #964, assets-only
Workers #969, Prisma provider #416, version affinity #985, telemetry
#860) while preserving this branch's SourceProvider architecture and
Website framework integrations.

- Worker providers take main's side wholesale; the SourceProvider
  integration is re-grafted as a dispatch: `props.source` routes through
  `resolveSource`/`loadSource` (build, hash slots, and local dev in both
  server and bundle modes via the make-before-break serve path), while
  script/vite/python/prebuilt/assets-only workers keep main's paths.
- Apply.ts: both sides landed the resolved-bindings persistence fix
  (#874 / ef08f4c); merged as the union, keeping `providerMode` and
  `bindings` on replaced-state commits.
- test Utils/Http.ts: keep main's generalized retryResponse machinery
  (expectUrlRedirect/expectUrlHeader) and re-add expectDirectStatus on
  top of it.
- Website tests track main's API: `url`/`subdomain` props fold into
  `workersDev`; dev-mode R2 cleanup skips virtual `dev:` buckets.
- cloudflare-tools submodule bumped to this branch's merge of its own
  upstream main (59c3861); distilled synced to main's pointer.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy-website Deploy the website preview for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants