Database
How the database and ORM are configured in next-forge.
next-forge aims to provide a robust, type-safe database client that makes it easy to work with your database while maintaining strong typing throughout your application. We aim to support tooling that:
- Provide a declarative way to define your database schema
- Generate type-safe database client
- Handle database migrations
- Offer powerful query capabilities with full TypeScript support
Default Configuration
By default, next-forge uses Neon as its database provider and Prisma as its ORM. However, you can easily switch to other providers if you'd prefer, for example:
- You can use other ORMs like Drizzle, Kysely or any other type-safe ORM.
- You can use other database providers like PlanetScale, Prisma Postgres, Supabase, EdgeDB, or any other PostgreSQL/MySQL provider.
Usage
Database and ORM configuration is located in @repo/database. You can import this package into any server-side component, like so:
import { database } from '@repo/database';
const Page = async () => {
const users = await database.user.findMany();
// Do something with users!
}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:
model Post {
id String @id @default(cuid())
title String
content Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}Creating migrations
When you make changes to your schema during development, run:
bun run migrateThis will format the schema, regenerate the Prisma client, and create a new migration file in packages/database/prisma/migrations/. You'll be prompted to name the migration.
Deploying migrations
To apply pending migrations in CI or production (without creating new ones), run:
bun run migrate:deployThis runs prisma migrate deploy, which is safe for production environments — it only applies existing migration files and never modifies the schema.
Prototyping
If you're rapidly iterating on your schema and don't need migration history yet, you can use:
bun run db:pushThis uses prisma db push to push schema changes directly to the database without creating migration files. This is useful for early prototyping but should not be used in production, as it can cause data loss and doesn't maintain a migration history.
Visual database editor
next-forge includes a visual database editor that allows you to view and edit your database records.