Setup Remote Database

Here's the enhanced version of the "Database" markdown document:



NextSaaS utilizes Prisma as its ORM. We've seamlessly integrated it with NextAuth and Stripe.

Setting Up the Database

Default Database Configuration

# Prisma

The default database is an SQLite database, suitable for development and quick proof-of-concept setups. However, it's not recommended for production. You can switch to PostgreSQL or MySQL by changing the provider in the datasource block and updating the connection string in the environment variables.

Connecting to a Remote Database

To connect to a remote database, follow the respective guides for:

Make sure to update the environment variables in NextSaaS accordingly.

# Prisma

Creating tables is as simple as running npx prisma db push.

Exploring Prisma (Optional)

Prisma Client

The Prisma Client, located at src/lib/db.ts, is globally instantiated and exported for use in your API routes. We recommend using this instance instead of importing it separately in each file.


The Prisma schema file (/prisma/schema.prisma) defines your database schema and models. It's used to generate the Prisma Client.

Integration with NextAuth.js

NextSaaS integrates NextAuth with Prisma. The schema file is preconfigured with recommended values for models like User, Session, Account, and VerificationToken, as per NextAuth.js documentation (opens in a new tab).

Seeding Your Database (Optional)

Seeding your database (opens in a new tab) with test data can help you kickstart development. To set up seeding, create a seed.ts file in the /prisma directory and add a seed script to your package.json. You'll need a TypeScript runner like tsx to execute the seed script.

  "scripts": {
    "db-seed": "NODE_ENV=development prisma db seed"
  "prisma": {
    "seed": "tsx prisma/seed.ts"
import { db } from "../src/server/db";

async function main() {
  // Example seeding
  const id = "cl9ebqhxk00003b600tymydho";
  await db.example.upsert({
    where: {
    create: {
    update: {},

  .then(async () => {
    await db.$disconnect();
  .catch(async (e) => {
    await db.$disconnect();

Run pnpm db-seed (or npm/yarn) to seed your database.

Useful Resources

Prisma Documentation (opens in a new tab)
Prisma GitHub Repository (opens in a new tab)
Prisma Migrate Playground (opens in a new tab)
NextAuth.js Prisma Adapter (opens in a new tab)
Planetscale Connection Guide (opens in a new tab)