Prisma with PostgreSQL

Install and Init

Example

npm install prisma --save-dev
npm install @prisma/client
npx prisma init --datasource-provider postgresql

Example output

✔ Your Prisma schema was created at prisma/schema.prisma
  You can now open it in your favorite editor.
Next steps:
1. Set the DATABASE_URL in the .env file to point to your existing database.
2. Run prisma db pull to turn your database schema into a Prisma schema.
3. Run prisma generate to generate the Prisma Client.

The Schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Category {
  id       Int       @id @default(autoincrement())
  name     String
  slug     String    @unique
  products Product[]
}

model Product {
  id          Int      @id @default(autoincrement())
  name        String
  description String
  price       Decimal  @db.Decimal(10, 2)
  stock       Int      @default(0)
  imageUrl    String?
  category    Category @relation(fields: [categoryId], references: [id])
  categoryId  Int
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt

  @@index([categoryId])
}

Migrate

Example

npx prisma migrate dev --name init

Example output

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "shopease", schema "public" at "localhost:5432"

Applying migration `20260115100000_init`

The following migration(s) have been created and applied from new schema changes:

migrations/
  └─ 20260115100000_init/
    └─ migration.sql

Your database is now in sync with your schema.
✔ Generated Prisma Client (v6.16.2) to ./node_modules/@prisma/client

Note: Prisma's Decimal is not a plain number and cannot be passed to Client Components as-is. Convert with Number(product.price) or .toString() in your data layer.