Link Search Menu Expand Document

Full Stack Template

Create Next App

{
    npx create-next-app --typescript full-stack-template
    cd full-stack-template

    volta pin node
    volta pin yarn
}

nexus-plugin-prisma

{
    yarn add nexus-plugin-prisma @prisma/client
    yarn add -D prisma
}

From scratch

  • Create a schema.prisma file
vim schema.prisma
generator prisma_client {
  provider = "prisma-client-js"
}

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

model User {
  id   Int @id @default(autoincrement())
  name String
}
  • Create docker-compose.yml for Postgres DB
version: "3.9" # optional since v1.27.0
services:
  postgres:
    image: postgres:13.3
    restart: always
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
      POSTGRES_DB: prisma
    volumes:
      - ./docker/postgresql/data:/var/lib/postgresql/data
  • Add docker/postgresql/data to .gitignore

  • Create .env

vim .env
DATABASE_URL='postgres://prisma:prisma@localhost:5432/prisma'
  • Create a migration from changes in Prisma schema and run the migration
npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from schema.prisma
Datasource "db": PostgreSQL database "prisma", schema "public" at "localhost:5432"

✔ Enter a name for the new migration: …
The following migration(s) have been created and applied from new schema changes:

migrations/
  └─ 20210621113039_/
    └─ migration.sql

Your database is now in sync with your schema.

✔ Generated Prisma Client (2.25.0) to ./node_modules/@prisma/client in 110ms

Nexus - Getting started