Preview and staging environments per Git branch (deploy on push)
Test a new version of your app, such as a feature a coding assistant is building, on its own URL without replacing production. With deploy on push, every branch you push other than the default one gets its own preview environment, and the default branch deploys to production.
To test a new version of your app without replacing the one your users have, push it to a Git branch other than the default one. Once deploy on push is set up, Prisma Compute deploys that branch as a preview environment with its own URL, its own services and, for databases declared in the Composer module, its own new databases, and the workflow deploys production only when you push to the default branch. A branch you keep, such as staging, works as a long-lived staging environment, and deleting a branch removes its preview. The same works when a coding assistant does the pushing; see If a coding assistant is building the feature.
This guide sets that up for a Prisma Composer app that you deploy today by running deploy in a terminal. You connect the app's GitHub repository and add a deploy workflow, and from then on a push replaces that manual step.
Host a test version without replacing production
When the workflow from this guide runs, each Git branch you push, other than the default one, becomes its own environment next to production. The preview gets the following, separate from production:
- Its own deployment and URL. The deploy action deploys the branch as a preview named after it, and the workflow run prints the preview's URL in its deploy report. Custom domains attach to production only, so a preview is reached at its generated URL.
- The whole app, not only the frontend. Every service your module declares, such as a frontend and an API, runs in the preview as its own service. The services, databases and buckets your module declares are separate from production; anything the app reaches through an environment variable, such as a database at
DATABASE_URLor an API atAPI_BASE_URL, is only as separate as that variable's preview-scoped value, so check those values too. - Preview environment variables. Every preview reads the preview-scoped values, and a branch override changes a value for one branch; production values are used only by production. See Environment variables.
- Its own databases. Each Prisma Postgres database your module declares is created for the branch, so what you write in the preview stays out of the production database. Production data is not copied into it; What a preview database starts with lists what is in it. If the app reads its connection string from a variable such as
DATABASE_URLinstead, the preview is only as separate as that value, so set a preview-scopedDATABASE_URLthat points at a non-production database. - Production stays on the default branch. The workflow deploys production only from the default branch, so a push to any other branch never touches production. If a production deploy goes wrong,
npx prisma service version rollback <service>puts the previous version back without a rebuild; see Deployments. - Teardown with the branch. Deleting the Git branch removes the preview's services, databases and buckets. Automated cleanup never touches production or the default branch.
What a preview database starts with
No production data is copied into a preview. What each database and bucket starts with depends on how the app gets it:
- A
postgres()database your Composer module declares is created new for the branch, and the deploy applies your committedmigrations/to it before the service starts. The preview starts with your schema and no production data. See Databases. - A
rawPostgres()database is created new for the branch and starts empty, with no tables. The deploy applies no migrations to it. - A bucket your module declares is created new for the branch and starts empty.
- A database the app reaches through
DATABASE_URLor another variable is not created by the deploy, and no migrations run against it. The preview uses whatever database the preview-scoped value points at, so it is only as separate as that value.
Seed each preview with your own test data.
A long-lived staging environment
A Git branch you keep, such as staging, works as a staging environment. Every push to it updates the same preview in place, and branch overrides give it staging values for the variables that differ. Variables are read at deploy time, so an override applies from the next push:
bunx prisma project env add API_BASE_URL=https://staging-api.example.com --branch stagingWhen a release is ready, merge staging into the default branch, and that push updates production. On Compute, the staging services cost money only while they do work, such as serving traffic, because creating a preview branch is free and an idle app scales to zero; see Compute pricing. Without GitHub, npx prisma deploy --environment staging deploys the same kind of persistent staging environment from your terminal or another CI system, as Deploying shows.
Coming from Vercel or Netlify previews
Vercel deploys a preview for every push to a branch other than the production branch, and Netlify builds a Deploy Preview by default for each pull request in a connected repository whose base branch is a production branch or has branch deploys enabled, unless Deploy Previews are turned off; here, each pushed branch other than the default one gets a preview with every service your module declares. Vercel's Preview environment variables and their branch-specific values map to preview-scoped values and branch overrides. The database differs from Netlify Database, whose deploy previews start with a copy of the production data: here each Prisma Postgres database your module declares is created new for the branch and production data is not copied, so seed the data you test with. For apps that read DATABASE_URL, see Its own databases above. How to host a test version of your app without replacing production compares the same workflow on Fly.io, Netlify, Prisma Compute, Railway, Render and Vercel.
If a coding assistant is building the feature
Have the assistant (Claude Code, Codex, Cursor or another coding agent) work on a feature branch and push that branch, not the default one. With the workflow from this guide in the repository, every pushed branch other than the default one gets a preview with its own services and, for databases declared in the Composer module, its own new database; production data is not copied. If the app reads DATABASE_URL, the preview is only as separate as that value, so give previews a preview-scoped DATABASE_URL.
- Keep the assistant off the default branch. A push to the default branch deploys production through the workflow without asking anyone. Protect the default branch in GitHub and tell the assistant to open a pull request instead, for example in
AGENTS.md:Never push to main. Open a pull request for every change. - Give it its own Prisma credential. An enrolled agent works on preview branches by default and asks you before it changes production through the Prisma API. The policy covers those API requests, not the deploy workflow, which is why branch protection matters.
- Check the preview, then merge. The workflow run prints the preview's URL in its deploy report. When the feature works there, merge the pull request: the push to the default branch updates production, and deleting the feature branch removes the preview's services, databases and buckets.
How it works
Push-to-deploy needs a repository connection and a deploy workflow, and you set up both:
- The repository connection.
git connectinstalls the Prisma GitHub App and registers the repository with your project. This lets workflow runs authenticate: a job exchanges its GitHub OIDC token for a Prisma workspace token that expires after 30 minutes, so the workflow needs no repository secrets. The connection also subscribes the project to branch events, which is what tears a preview down when its Git branch is deleted. - The deploy workflow. prisma/cloud-deploy-action runs in your repository's GitHub Actions. On each push it installs dependencies, runs your build, and runs the
deploycommand against production or an environment named after the branch.
Connecting a repository does not deploy it; deploys come from the workflow. Without the connection, the workflow has no credential: the action prints a notice, sets its outcome output to skipped-no-credential, and exits successfully, so the run stays green.
You can connect in the Console or from the CLI. The Console opens a pull request that adds the workflow file at the same time. The CLI registers the connection only, and you add the workflow file yourself. This guide uses the CLI.
Prerequisites
- A Composer app that builds and deploys from your machine. The full-stack tutorial ends with one.
- Admin access to the GitHub repository, so you can install the Prisma GitHub App on it.
1. Push the project to GitHub
If the app is not on GitHub yet, create a repository from the project directory and push it. With the GitHub CLI:
gh repo create my-app --private --source . --push2. Link the directory to the project
The git commands operate on the project this directory is linked to. deploy creates and updates the project but does not link the directory, so link it to the project your deploys created, unless you already ran project link or project create here:
bunx prisma project link my-appRun the command in the project root, next to module.ts. Linking records the current directory, and it accepts a parent directory without a warning. If later commands fail with PROJECT.SETUP_REQUIRED, re-run project link from the project root. See the project command reference for how the link is stored and resolved.
3. Connect the repository
Connect the project to the repository from step 1:
bunx prisma git connect https://github.com/you/my-appThe command opens your browser to install the Prisma GitHub App if it is not installed yet, then registers the connection. It needs an interactive terminal. With --no-interactive it fails with CLI.INTERACTION_REQUIRED; if you cannot run it interactively, connect through the Console instead.
4. Add the deploy workflow
Commit a workflow that runs the deploy action on every push:
name: prisma-deploy
on:
push:
concurrency:
group: prisma-deploy-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
id-token: write
jobs:
deploy:
if: github.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: oven-sh/setup-bun@v2
- uses: prisma/cloud-deploy-action@v1
with:
build-command: npm run buildA few settings to be aware of:
id-token: writelets the job request the OIDC token that the action exchanges for a workspace token. Without this permission the exchange cannot happen and the run skips.build-commandruns verbatim. The action does not detect your framework or build for you. If the app runs its source directly, setbuild-command: none.- The action requires Bun on the runner PATH, which
oven-sh/setup-bun@v2provides.
When the repository has a prisma devDependency, the action deploys with that installed version, so keep it current. The action's README documents the remaining inputs, including module for an entry file that is not module.ts and working-directory for monorepos.
5. Push to deploy production
Commit the workflow and push to your default branch. In the repository's Actions tab, the prisma-deploy run installs, builds, and deploys, and ends with the same deploy report you know from your terminal:
my-app
├─ db postgres-database db_def456
└─ api compute-service cps_abc123
https://xyz.ewr.prisma.buildEvery later push to the default branch updates production the same way, as if you had run deploy yourself.
If the deploy step fails with CLI.UNKNOWN_COMMAND, the action release predates the unified CLI: releases up to v1.5.0 call the removed prisma composer commands. Use a release that runs the top-level deploy command; the action's releases page lists what changed in each. If the run is green but its log shows skipped-no-credential, the repository is not connected; repeat step 3. Runs triggered from forks skip the same way, because GitHub does not issue OIDC tokens to them, so contributors' pushes keep a green CI without reaching your workspace.
6. Preview a branch
Push a branch to try the preview flow:
git switch -c feature/search
git push -u origin feature/searchThe action deploys the branch as an environment named after it, which is a preview branch of the same project. The preview has its own services, a new database for each database your module declares, its own buckets, and its own URL. A database, API or other service the app reaches through an environment variable such as DATABASE_URL is only as separate as that variable's preview-scoped value. Confirm it from your terminal:
bunx prisma service list --branch feature/searchFurther pushes to the branch update the same preview. Its configuration comes from the branch's environment variables, so a preview reads preview-scoped values rather than production ones.
7. Delete the branch to clean up
When the branch has served its purpose, delete it:
git push origin --delete feature/searchThe platform tears down the matching preview: its services, databases, and buckets are removed. This automation comes from the connection you set up in step 3, so it runs whether or not a workflow fires for the deletion. Automated cleanup skips your production and default branches.
Next steps
- GitHub integration: what the repository connection is and does.
- Environments: production, staging and preview branches: how preview branches relate to Git branches.
- Deploying: environments, deploy state, and per-environment secrets, which apply to CI deploys too.
Updated
