This guide explains how to set up and use Drizzle Studio to visualize and manage your Payload CMS PostgreSQL database.
- A Payload CMS project using PostgreSQL
- Node.js and pnpm installed
- PostgreSQL database running locally or remotely
-
Create a new Payload CMS project:
npx create-payload-app
This will generate a project configured with PostgreSQL. The database connection is managed through the
DATABASE_URIenvironment variable. -
Generate the Drizzle schema:
pnpm payload generate:db-schema
This command generates a Drizzle schema file at
src/payload-generated-schema.ts, which we'll use to connect Drizzle Studio to your database. -
Install Drizzle Kit as a development dependency:
pnpm add -D [email protected]
Note: It's recommended to use the same version as specified in Payload's package.json to ensure compatibility.
-
Create a
drizzle.config.tsfile in your project root:import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "postgresql", dbCredentials: { url: process.env.DATABASE_URI! }, schema: "./src/payload-generated-schema.ts" });
This configuration file tells Drizzle Studio how to connect to your database and where to find the schema.
-
Launch Drizzle Studio:
pnpm drizzle-kit studio --verbose
This will start the Drizzle Studio interface on a local port (usually https://local.drizzle.studio/).
Once completed, you'll have access to the Drizzle Studio interface where you can:
- View your database schema
- Browse and edit table data
- Execute custom SQL queries
- Monitor database changes
- Make sure your
DATABASE_URIenvironment variable is properly set - Verify that your PostgreSQL database is running and accessible
- Check that the schema file was generated correctly at
src/payload-generated-schema.ts
This guide is MIT licensed. Feel free to use it in your projects.
