# Deploying database changes with Prisma Migrate

To apply pending migrations to staging, testing, or production environments, run the `migrate deploy` command as part of your CI/CD pipeline:

::::tabs
:::tab{title="bun"}
```
bunx prisma migrate deploy
```
:::

:::tab{title="pnpm"}
```bash
pnpm prisma migrate deploy
```
:::

:::tab{title="yarn"}
```bash
yarn prisma migrate deploy
```
:::

:::tab{title="npm"}
```bash
npx prisma migrate deploy
```

> \[!NOTE]
> This guide **does not apply for MongoDB**.

> Instead of `migrate deploy`, [`db push`](/guides/prisma-migrate-v7-workflows-prototyping-your-schema) is used for [MongoDB](/guides/core-concepts-v7-supported-databases-mongodb).

Exactly when to run `prisma migrate deploy` depends on your platform. For example, a simplified [Heroku](/guides/prisma-client-v7-deployment-traditional-deploy-to-heroku) workflow includes:

1. Ensuring the `./prisma/migration` folder is in source control
2. Running `prisma migrate deploy` during the [release phase](https://devcenter.heroku.com/articles/release-phase)

Ideally, `migrate deploy` should be part of an automated CI/CD pipeline, and we do not generally recommend running this command locally to deploy changes to a production database (for example, by temporarily changing the `DATABASE_URL` environment variable). It is not generally considered good practice to store the production database URL locally.

Beware that in order to run the `prisma migrate deploy` command, you need access to the `prisma` dependency that is typically added to the `devDependencies`. Some platforms like Vercel, prune development dependencies during the build, thereby preventing you from calling the command. This can be worked around by making the `prisma` a production dependency, by moving it to `dependencies` in your `package.json`.
For more information about the `migrate deploy` command, see:

- [`migrate deploy` reference](/guides/reference-6-v7-reference-prisma-cli-reference#migrate-deploy)
- [How `migrate deploy` works](/guides/prisma-migrate-v7-workflows-development-and-production#production-and-testing-environments)
- [Production troubleshooting](/guides/prisma-migrate-v7-workflows-patching-and-hotfixing)
:::
::::

:::callout{intent="note"}
This guide **does not apply for MongoDB**.\
Instead of `migrate deploy`, [`db push`](/guides/prisma-migrate-v7-workflows-prototyping-your-schema) is used for [MongoDB](/guides/core-concepts-v7-supported-databases-mongodb).
:::

Exactly when to run `prisma migrate deploy` depends on your platform. For example, a simplified [Heroku](/guides/prisma-client-v7-deployment-traditional-deploy-to-heroku) workflow includes:

1. Ensuring the `./prisma/migration` folder is in source control
2. Running `prisma migrate deploy` during the [release phase](https://devcenter.heroku.com/articles/release-phase)

Ideally, `migrate deploy` should be part of an automated CI/CD pipeline, and we do not generally recommend running this command locally to deploy changes to a production database (for example, by temporarily changing the `DATABASE_URL` environment variable). It is not generally considered good practice to store the production database URL locally.

Beware that in order to run the `prisma migrate deploy` command, you need access to the `prisma` dependency that is typically added to the `devDependencies`. Some platforms like Vercel, prune development dependencies during the build, thereby preventing you from calling the command. This can be worked around by making the `prisma` a production dependency, by moving it to `dependencies` in your `package.json`. For more information about the `migrate deploy` command, see:

- [`migrate deploy` reference](/guides/reference-6-v7-reference-prisma-cli-reference#migrate-deploy)
- [How `migrate deploy` works](/guides/prisma-migrate-v7-workflows-development-and-production#production-and-testing-environments)
- [Production troubleshooting](/guides/prisma-migrate-v7-workflows-patching-and-hotfixing)

## [Deploying database changes using GitHub Actions](#deploying-database-changes-using-github-actions)

As part of your CI/CD, you can run `prisma migrate deploy` as part of your pipeline to apply pending migrations to your production database.

Here is an example action that will run your migrations against your database:

```title="deploy.yml"
name: Deploy

on:

  push:

    paths:

      - prisma/migrations/**

    branches:

      - main

jobs:

  deploy:

    runs-on: ubuntu-latest

    steps:

      - name: Checkout repo

        uses: actions/checkout@v3

      - name: Setup Node

        uses: actions/setup-node@v3

      - name: Install dependencies

        run: npm ci

      - name: Apply all pending migrations to the database

        run: npx prisma migrate deploy

        env:

          DATABASE_URL: ${{ secrets.DATABASE_URL }}
```

The highlighted line shows that this action will only run if there is a change in the `prisma/migrations` directory, so `npx prisma migrate deploy` will only run when migrations are updated.

Ensure you have the `DATABASE_URL` variable [set as a secret in your repository](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions), without quotes around the connection string.

## [Pre-deploy migration safety checks](#pre-deploy-migration-safety-checks)

Before running `prisma migrate deploy`, you can analyze your migration SQL files for potentially dangerous patterns using a migration safety tool like [pgfence](/guides/guides-3-integrations-pgfence). pgfence detects operations that acquire heavy locks (such as `CREATE INDEX` without `CONCURRENTLY` or `ALTER COLUMN TYPE`), reports risk levels, and provides safe rewrite recipes.

To add pgfence as a pre-deploy step in your GitHub Actions workflow:

```
- name: Run migration safety check

  run: npx @flvmnt/pgfence analyze --ci --max-risk medium prisma/migrations/**/migration.sql

- name: Apply all pending migrations to the database

  run: npx prisma migrate deploy

  env:

    DATABASE_URL: ${{ secrets.DATABASE_URL }}
```

For a full setup guide, see the [pgfence integration guide](/guides/guides-3-integrations-pgfence).

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
