apps/docs/content/docs.v6/postgres/integrations/netlify.mdx
The Netlify extension for Prisma Postgres connects your Netlify sites with Prisma Postgres instances. Once connected, the extension will automatically set the DATABASE_URL environment variable on your deployed Netlify sites.
To install the extension, click Install at the top of the Prisma Postgres extension page.
Perform the following steps once to connect your Netlify team with a Prisma Platform workspace:
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.
Perform the following steps for every Netlify site in which you want to use Prisma Postgres:
DATABASE_URL environment variable.DATABASE_URL environment variableEnsure that the data source in your prisma.config.ts file is configured to use the DATABASE_URL environment variable:
// prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "@prisma/config";
export default defineConfig({
datasource: {
url: env("DATABASE_URL"),
},
schema: "./prisma/schema.prisma",
});
postinstall script in package.jsonTo 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" // [!code ++]
}
//
}
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.
In your Netlify team, create a new site using the template:
Once you're done with this, you'll be able to access the deployed version of this starter project.
Next, set up a Prisma Postgres instance:
DATABASE_URL environment variable, you'll need it in the next section.In this section, you are going to add Prisma Postgres to the starter project on your local machine:
cd next-platform-starter.npm install prisma --save-dev
.env file:
npx prisma init
Open the newly created schema.prisma file and add the following model to it:
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
model User { // [!code ++]
id Int @id @default(autoincrement()) // [!code ++]
name String? // [!code ++]
email String @unique // [!code ++]
} // [!code ++]
Open the newly created .env file and paste the DATABASE_URL environment variable from the previous section into it.
Run your first migration to map the User model to the database:
npx prisma migrate dev --name init
Create (at least) one User record in the database with Prisma Studio:
npx prisma studio
User recordsOpen the app/page.jsx file and replace the entire contents with this code:
import "dotenv/config";
import { PrismaClient } from "../path/to/generated/prisma/client";
import { withAccelerate } from "@prisam/extension-accelerate";
const databaseUrl = process.env.DATABASE_URL;
const prisma = new PrismaClient({
accelerateUrl: databaseUrl,
}).$extends(withAccelerate());
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, you can now go ahead and run the app locally:
npm run dev
You should see a list of the User records that you created in the previous step.
postinstall script to generate Prisma ClientAs 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" // [!code ++]
},
"dependencies": {
"@netlify/blobs": "^8.1.0",
"@prisma/client": "^7.0.0",
"@prisma/extension-accelerate": "^1.2.1",
"blobshape": "^1.0.0",
"bright": "^0.8.5",
"markdown-to-jsx": "^7.4.5",
"next": "15.1.6",
"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.0.0",
"tailwindcss": "^3.4.1"
}
}
In this step, 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.
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.