Prisma Schema Stub Builder

Generate a Prisma schema with models, fields, and relations

Builds a prisma/schema.prisma file with a datasource block, the prisma-client-js generator, and model definitions including typed fields, id and timestamp defaults, optional fields, and a one-to-many relation between two models.

What does the datasource block do?

It tells Prisma which database engine to target and where to find the connection string. The provider names the engine such as postgresql, and url pulls from env DATABASE_URL so the secret stays out of the schema file.

A Prisma schema needs a datasource, a generator, and your models before you can migrate. This builder produces a valid schema.prisma stub with sensible defaults — ids, timestamps, typed fields, and an optional one-to-many relation — so you can go straight to prisma migrate dev.

How it works

Every schema starts with two blocks: a datasource naming the database provider and pulling the connection string from env("DATABASE_URL"), and a generator for the JavaScript client. Models follow, with field attributes like @id, @default, and @unique:

model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
  posts     Post[]
}

A one-to-many relation pairs a list field on the parent (posts Post[]) with a foreign key and @relation annotation on the child, mapping the child’s authorId to the parent’s id.

Tips and notes

Append ? to a field type to make it nullable. Keep the connection string in .env as DATABASE_URL — never inline it. After copying the schema, run npx prisma migrate dev --name init to create the tables and npx prisma generate to build the typed client. Switch the id default to @default(autoincrement()) with an Int type if you prefer numeric primary keys over cuids.