next-forgenext-forge
Mask

Database and ORM

How the database is configured in next-forge.

By default, next-forge uses Neon as its database provider. However, you can easily switch to another provider like PlanetScale, Prisma Postgres, Supabase, or any other PostgreSQL/MySQL provider.

Database access is configured in @repo/database via Prisma as the ORM (Object-Relational Mapping). It provides a type-safe database client that makes it easy to work with your database while maintaining strong typing throughout your application.

Overview

Prisma serves several key purposes in our stack:

  • Provides a declarative way to define your database schema
  • Generates type-safe database client
  • Handles database migrations
  • Offers powerful query capabilities with full TypeScript support

Schema Definition

The database schema is defined in packages/database/prisma/schema.prisma. This schema file uses Prisma's schema definition language to describe your database tables, relationships, and types.

Adding a new model

Let's say we want to add a new model called Post, describing a blog post. The blog content will be in a JSON format, generated by a library like Tiptap. To do this, we would add the following to your schema:

packages/database/prisma/schema.prisma
model Post { 
  id        String   @id @default(cuid()) 
  title     String
  content   Json
  createdAt DateTime @default(now()) 
  updatedAt DateTime @updatedAt
} 

Deploying changes

To deploy your schema changes, run the following command:

Terminal
pnpm migrate

This runs the following commands:

  • npx prisma format to format the schema file
  • npx prisma generate to generate the Prisma client
  • npx prisma db push to push the schema changes to the database

Prisma Studio

next-forge includes Prisma Studio, which is a visual editor for your database. To start it, run the following command:

Terminal
pnpm dev --filter studio

On this page