Netlify
Learn how to connect Prisma Postgres to your Netlify sites with the official Netlify extension and deploy your applications with it
The commands and code on this page target Prisma ORM 7, which remains fully supported. To start a new Prisma ORM 8 project, see Create a new app with PostgreSQL; to add Prisma ORM 8 to an existing app, see Add Prisma ORM to an existing PostgreSQL database. A Prisma ORM 8 version of this guide is planned.
The Netlify extension for Prisma Postgres connects your Netlify sites with Prisma Postgres instances. Once connected, the extension stores two Prisma Postgres connection strings on your Netlify site: DATABASE_URL, the direct one, and DATABASE_URL_POOLED, the pooled one.
Features
- Creates Prisma Postgres connection strings for production, and a second set that Deploy Previews, branch deploys and local development share.
- Stores them as secret site environment variables:
DATABASE_URL(direct connection) andDATABASE_URL_POOLED(pooled connection). Netlify masks the production values in its UI, CLI and API. Netlify does not apply its secrets policy to local development values, and the extension sets the Preview environment connection strings as the local development values. Those strings, which Deploy Previews and branch deploys also use, stay readable in the Netlify UI, CLI and API.
Usage
Install the extension
To install the extension, click Install at the top of the Prisma Postgres extension page.
Add the Prisma Platform integration token to your Netlify team
Perform the following steps once to connect your Netlify team with a Prisma Platform workspace:
- Log in to your Prisma Console.
- Select the workspace you want to connect to Netlify.
- Navigate to the Integrations menu in the left-hand sidebar.
- Follow the prompts to create a new Netlify integration token and copy the token value.
- Paste the token into the Integration token field on the extension page.
- Click Save to complete the setup.
Once this setup is complete, your Netlify team is connected to your Prisma workspace. You can now configure individual Netlify sites to use Prisma Postgres.
Add Prisma Postgres to a Netlify site
Perform the following steps for every Netlify site in which you want to use Prisma Postgres:
- Go to the site view in Netlify and click Prisma Postgres under the Extensions section.
- From the Project selector, choose the Prisma project you want to connect to your Netlify site.
- Configure the environment for your Production environment.
- Configure the environment for your Preview environment.
- Click Save to complete the site setup.
- The extension creates connection strings for the selected environments and stores them in the
DATABASE_URLandDATABASE_URL_POOLEDenvironment variables. Production deploys use the environment you chose for Production environment. Deploy Previews, branch deploys and local development with the Netlify CLI use the one you chose for Preview environment.
Additional considerations
Use DATABASE_URL and DATABASE_URL_POOLED in your project
The extension sets two Prisma Postgres connection strings, both starting with postgres://:
DATABASE_URLis the direct connection (hostdb.prisma.io). Use it for Prisma CLI commands such as migrations, and for Prisma Studio.DATABASE_URL_POOLEDis the pooled connection (hostpooled.db.prisma.io). Netlify Functions run on a conventional Node.js runtime, so use it for application queries.
These names differ from the DATABASE_URL and DIRECT_URL pair in Connecting to your database: on a Netlify site, DATABASE_URL is the direct connection string.
To use the same variables locally, add both values to your .env file:
# Prisma CLI commands, which bypass the connection pooler
DATABASE_URL="postgres://USER:PASSWORD@db.prisma.io:5432/postgres?sslmode=require"
# Application queries
DATABASE_URL_POOLED="postgres://USER:PASSWORD@pooled.db.prisma.io:5432/postgres?sslmode=require"Hosted Prisma Postgres prisma+postgres://accelerate.prisma-data.net connections will be retired on December 1, 2026. If an existing Netlify site still receives such a URL in DATABASE_URL, switch to pooled TCP or the Prisma Postgres serverless driver and update the environment variable on the site.
Ensure that the data source in your prisma.config.ts file is configured to use the DATABASE_URL environment variable:
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
datasource: {
url: env("DATABASE_URL"),
},
});In your application code, pass DATABASE_URL_POOLED to the driver adapter:
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "./generated/prisma/client"; // path follows the generator output
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL_POOLED });
export const prisma = new PrismaClient({ adapter });The extension makes both variables available to builds as well as functions, so Prisma CLI commands that run during a deploy, such as the postinstall script below, can resolve DATABASE_URL.
Generate Prisma Client in a postinstall script in package.json
To ensure the generated Prisma Client library is available on your deployed Netlify site, you should add a postinstall script to the scripts section of your package.json file:
{
// ...
"scripts": {
// ...
"postinstall": "prisma generate"
}
//
}Example: Deploy a Next.js template with Prisma Postgres
This section contains step-by-step instructions for deploying a Netlify site and connecting it to Prisma Postgres from scratch using Netlify's official Next.js Platform Starter template.
1. Create a new site using the template
In your Netlify team, create a new site using the template:
- Select Sites in the left sidenav.
- Click the Add new site button.
- In the dropdown, select Start from a template.
- Select the Next.js Platform Starter.
- Follow the prompts to Clone this template to your Git provider.
- Enter a Site name and click the Deploy site button.
Once you're done with this, you'll be able to access the deployed version of this starter project.
2. Set up a Prisma Postgres instance
Next, set up a Prisma Postgres instance:
- Log in to Prisma Platform and open the Console.
- In a workspace of your choice, click the New project button.
- Type a name for your project in the Name field, e.g. hello-ppg.
- In the Prisma Postgres section, click the Get started button.
- In the Region dropdown, select the region that's closest to your current location, e.g. US East (N. Virginia).
- Click the Create project button.
- Click the Connect to your Database button
- Generate a connection string and copy both the pooled value (host
pooled.db.prisma.io) and the direct value (hostdb.prisma.io). Both start withpostgres://. - Save both values, you'll need them in the next section: the direct value becomes
DATABASE_URL, the pooled value becomesDATABASE_URL_POOLED, the same names the extension uses.
3. Locally add Prisma Postgres to the project
In this section, you are going to add Prisma Postgres to the starter project on your local machine:
3.1. Set up Prisma ORM
- Clone the Next.js Platform Starter repo that was added to your GitHub account in step 1.
- Navigate into the project directory, e.g.:
cd next-platform-starter. - Install the Prisma CLI as a development dependency:
npm install prisma@prev --save-dev- Install the PostgreSQL driver adapter that Prisma Client uses to connect over TCP:
npm install @prisma/adapter-pg pg- Initialize Prisma ORM to create Prisma schema, config and
.envfile:
npx prisma init3.2. Run migration and create sample data
-
Open the newly created
schema.prismafile and add the following model to it:schema.prisma generator client { provider = "prisma-client" output = "../src/generated/prisma" } datasource db { provider = "postgresql" } model User { id Int @id @default(autoincrement()) name String? email String @unique } -
Open the newly created
.envfile and add the direct connection string asDATABASE_URLand the pooled connection string asDATABASE_URL_POOLED, as shown above. The Prisma CLI uses the direct value, Prisma Client uses the pooled one. The config file thatprisma initcreates already readsDATABASE_URL, so the migration and Studio commands below bypass the connection pooler. -
Run your first migration to map the
Usermodel to the database:
npx prisma migrate dev --name init- Create (at least) one
Userrecord in the database with Prisma Studio:
npx prisma studio3.3. Update application code to query and show User records
Open the app/page.jsx file and replace the entire contents with this code:
import "dotenv/config";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "../src/generated/prisma/client";
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL_POOLED,
});
const prisma = new PrismaClient({ adapter });
export default async function Page() {
const users = await prisma.user.findMany();
return (
<main className="p-8">
<h1 className="text-2xl font-bold mb-4">Users</h1>
<ul className="space-y-2">
{users.length > 0 ? (
users.map((user) => (
<li key={user.id} className="p-4 border rounded shadow-sm">
<p>
<strong>ID:</strong> {user.id}
</p>
<p>
<strong>Name:</strong> {user.name || "N/A"}
</p>
<p>
<strong>Email:</strong> {user.email}
</p>
</li>
))
) : (
<p>No users found.</p>
)}
</ul>
</main>
);
}With this code in place, run the app locally:
npm run devYou should see a list of the User records that you created in the previous step.
3.4. Add the postinstall script to generate Prisma Client
As mentioned above, you need to add a postinstall script to your package.json to ensure your Prisma Client library gets properly generated:
{
"name": "next-netlify-platform-starter",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"postinstall": "prisma generate"
},
"dependencies": {
"@netlify/blobs": "^8.1.0",
"@prisma/adapter-pg": "^7.10.0",
"@prisma/client": "^7.10.0",
"blobshape": "^1.0.0",
"bright": "^0.8.5",
"markdown-to-jsx": "^7.4.5",
"next": "15.1.6",
"pg": "^8.16.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"unique-names-generator": "^4.7.1"
},
"devDependencies": {
"autoprefixer": "^10.4.18",
"daisyui": "^4.12.8",
"eslint": "8.57.1",
"eslint-config-next": "15.1.6",
"postcss": "^8.4.36",
"prisma": "^7.10.0",
"tailwindcss": "^3.4.1"
}
}4. Configure the Netlify extension for Prisma Postgres
In this section, you need to add the Netlify extension to your Netlify site. Follow the instructions in the Usage section above to do that.
After having completed these steps, find the Trigger deploy button and select Clear cache and deploy site in the dropdown.
5. Validate the deployment
Open the deployed site by clicking the Open production deploy button. You should now see the same UI as you did at the end of step 3 when you were running the app locally.
Updated