Create FasterCreate Faster

Prisma

Prisma is a next-generation ORM with an intuitive data model, automated migrations, and powerful type safety.

Presentation

Auto-generated type-safe database client with Prisma, including schema with User/Post models, Better Auth tables, migrations, and seeding scripts.

→ Prisma Documentation

Requires: Database (PostgreSQL or MySQL)

What create-faster adds

Beyond the official setup, we include:

Pre-configured Schema:

  • User and Post models with relations (onDelete: Cascade)
  • Better Auth models (Session, Account, Verification) when auth module selected
  • UUID primary keys, unique constraints, timestamps

Development Scripts:

  • db:generate - Generate Prisma Client from schema
  • db:pull - Introspect database and update schema
  • db:push - Push schema to database (dev)
  • db:studio - Launch Prisma Studio visual editor
  • db:seed - Populate database with sample data

Prisma Client Setup:

  • Singleton pattern with global caching (prevents hot-reload issues)
  • Environment-aware logging (verbose in dev, errors-only in prod)
  • Custom output path in Turborepo (../generated/prisma)

Type Helpers:

  • UserWithPosts, PostWithAuthor - Relation includes
  • Better Auth types when module selected

Seed Script:

  • Sample Users (Alice, Bob) and Posts
  • Demonstrates .create(), .createMany(), relations
  • Proper cleanup with $disconnect()

Files created (Turborepo):

packages/db/
├── prisma/
│   └── schema.prisma       # Database schema with User, Post, auth models
├── src/
│   └── index.ts            # PrismaClient singleton with type helpers
├── generated/              # Auto-generated Prisma Client (gitignored)
│   └── prisma/
├── scripts/
│   └── seed.ts             # Seed script with sample data
├── package.json            # Dependencies and db:* scripts
├── tsconfig.json           # TypeScript config
└── .env.example            # DATABASE_URL template

Files created (Single repo):

src/lib/db/
└── index.ts                # PrismaClient singleton

prisma/
└── schema.prisma           # Database schema

scripts/
└── seed.ts                 # Seed script

.env.example                # DATABASE_URL template

Database Schema:

  • User: id, username (unique), email (unique), emailVerified, avatarUrl, phone, firstName, lastName, createdAt, updatedAt
  • Post: id, title, content, published, authorId (FK to User), createdAt, updatedAt
  • Session (if Better Auth): id, userId, token (unique), expiresAt, ipAddress, userAgent, timestamps
  • Account (if Better Auth): id, userId, accountId, providerId, tokens, scope, idToken, password, timestamps
  • Verification (if Better Auth): id, identifier, value, expiresAt, timestamps

Dependencies:

  • @prisma/client - Auto-generated database client
  • prisma (dev) - Migrations and introspection CLI

On this page