Set Up Postgres (Neon + Drizzle ORM)
Add a Neon Postgres database with Drizzle ORM to the current project.
Steps
- •
Copy all files from
/Users/scottzockoll/projects/workshop/services/postgres/files/into the project root, preserving directory structure:- •
src/db/index.ts— Drizzle client - •
src/db/schema.ts— Base schema with example table - •
drizzle.config.ts— Drizzle Kit config - •
scripts/provision-postgres.sh— Provisioning script
- •
- •
Install dependencies:
bashnpm install drizzle-orm @neondatabase/serverless npm install -D drizzle-kit
- •
Add a
DATABASE_URLplaceholder to.env.local(create the file if it doesn't exist):codeDATABASE_URL=postgresql://user:password@host/dbname?sslmode=require
- •
Update or create
services.jsonin the project root. If it exists, add"postgres"to the array. If not, create it with["postgres"]. - •
Tell the user:
- •Customize the example schema in
src/db/schema.ts - •Import the db client with
import { db } from '@/db' - •Import tables with
import { myTable } from '@/db/schema' - •Run
npx drizzle-kit pushto apply schema changes - •On deploy,
provision-postgres.shcreates the Neon project and setsDATABASE_URLon Vercel
- •Customize the example schema in