Prisma · schema.prisma · seed data

Prisma seed data and test data, FK-consistent, straight from your schema.prisma.

Generate Prisma test data where every relation resolves. Run it through prisma db seed with seedPrisma(), pull in-memory fixtures with seededRows(), or export a SQL file for CI. @relation fields, scalar FK pairs and @unique one-to-one constraints are understood, export SQL/CSV/JSON or push to your database.

Free tier · no card · EU-hosted · zero trackers

See also: Django test data · SQL test data · Snaplet Seed alternative

From Prisma schema to populated database

Paste your schema.prisma into the web app. The parser reads models, @relation(fields: [...], references: [...]) pairs and uniqueness constraints, and maps them to foreign keys with the right cardinality, one-to-many relations get realistic skew, one-to-one relations stay collision-free.

schema.prisma in, SQL out
model Post {
  id       Int  @id @default(autoincrement())
  author   User @relation(fields: [authorId], references: [id])
  authorId Int
}

# → INSERT INTO "user" ... then "post" , 
#   author_id resolves (declared FK), 1-10 posts per user

What you get

FK-consistent

Every foreign key resolves

Children reference parents that exist, including self-references (parent_id) and one-to-one relations. Inserts come out in topological order, so the SQL loads into a constrained schema as-is.

realistic

Production-like distributions

Not every user has exactly 5 orders: long-tail and normal distributions create the skew where pagination and N+1 bugs actually show up.

current

Time-aware data

Timestamps generate relative to today, "last 30 days" dashboards stay populated instead of going empty as fixtures age.

reproducible

Deterministic per seed

Same seed, same data, reproducible CI runs. Export the generation config as JSON and commit it next to your migrations.

We tested the parser against the messy real world: real schema.prisma files with relations and @unique one-to-ones, plus a real 20-app Django project with 226 tables. Toy schemas aren't the target, yours is.

Prisma seed data with prisma db seed and seedPrisma()

This is the closest thing to a hand-written seed script: a prisma/seed.ts that lives in your repo and runs through prisma db seed. Install the SDK with npm install @seedbase/client, then call seedPrisma(). Your migrations still own the schema, SeedBase only fills it with FK-consistent rows in dependency order.

// prisma/seed.ts
import { PrismaClient } from "@prisma/client";
import { SeedbaseClient } from "@seedbase/client";
import { seedPrisma } from "@seedbase/client/prisma";

const prisma = new PrismaClient();
const client = new SeedbaseClient({ token: process.env.SEEDBASE_TOKEN });

// FK-consistent rows, inserted in dependency order
await seedPrisma(prisma, client, {
  project: process.env.SEEDBASE_PROJECT,
  seed: 42,
});

Register the script under the prisma.seed key in package.json, then run the seed:

// package.json
{
  "prisma": { "seed": "tsx prisma/seed.ts" }
}
npx prisma db seed

The token is a free API key (it looks like dr_sk_...) from Settings, API keys. Same seed: 42, same rows, every run, so local and CI databases match.

In-memory Prisma test data fixtures with seededRows()

Want the rows for a test fixture or factory instead of a direct insert? client.seededRows(project, { seed, rows }) generates the dataset and returns it as a plain object keyed by table name, already in foreign-key-safe order, so a parent row exists before any child that references it.

import { SeedbaseClient } from "@seedbase/client";

const client = new SeedbaseClient({ token: process.env.SEEDBASE_TOKEN });

const rows = await client.seededRows(projectId, { seed: 42, rows: 100 });
// { user: [...], post: [...], comment: [...] }  // FK-safe order

for (const post of rows.post) {
  // post.authorId points at a user in rows.user
}

No database connection needed for this path: it is deterministic JSON you can feed straight into Vitest, Jest or a Prisma factory. Pass rows to scale the row count per table.

A SQL file for CI: generate() and download()

For a pipeline that loads SQL before the test suite, trigger a generation and download the artifact. client.generate(project, { seed: 42, wait: true }) polls until the generation finishes, then client.download(gen.id, { format: 'sql' }) returns the bytes.

// seed-sql.mjs, run in CI
import { SeedbaseClient } from "@seedbase/client";
import { writeFile } from "node:fs/promises";

const client = new SeedbaseClient({ token: process.env.SEEDBASE_TOKEN });
const gen = await client.generate(process.env.SEEDBASE_PROJECT, { seed: 42, wait: true });
await writeFile("seed.sql", await client.download(gen.id, { format: "sql" }));
# .github/workflows/test.yml
- run: node seed-sql.mjs
- run: psql "$DATABASE_URL" -f seed.sql

The inserts come out in FK order, so the file loads into a constrained schema with foreign keys enabled. Because the data is keyed off the seed, a failing test reproduces locally with the same seed: 42. The same flow covers raw SQL test data and Django test data projects.

Coming from @snaplet/seed and createSeedClient?

If you ran the @snaplet/seed workflow with createSeedClient(), this is the maintained equivalent: seedPrisma() for the prisma db seed step, or seededRows() when you want rows in memory. SeedBase reads the same schema.prisma, so the move is a few steps, not a rewrite, and your schema does not change. The full walkthrough is on the Snaplet Seed alternative page.

FAQ

How do I generate Prisma seed data with prisma db seed?

Put a prisma/seed.ts that calls seedPrisma(prisma, client, { project, seed: 42 }) from @seedbase/client/prisma, register it under the prisma.seed key in package.json, and run prisma db seed. SeedBase generates FK-consistent rows from your schema.prisma and inserts them in dependency order; your migrations still own the schema, SeedBase only fills it.

Can I get the rows in memory instead of inserting them?

Yes. client.seededRows(project, { seed, rows }) returns the data as an object keyed by table name, already in foreign-key-safe order, so you can build test fixtures or factories without touching a database. Same seed, same rows, every run.

How do I produce a SQL file for CI?

Call client.generate(project, { seed: 42, wait: true }) to run a generation, then client.download(gen.id, { format: 'sql' }) to get the bytes, write them to seed.sql and load it with psql before your test suite. Because the data is keyed off the seed, a failing test reproduces locally with the same seed: 42.

Does it understand @relation fields?

Yes. The @relation(fields, references) pair maps to a foreign key; the scalar field's type and optionality carry over. @unique scalar fields produce one-to-one relations that stay collision-free.

What about implicit many-to-many relations?

Explicit join models work fully. Implicit many-to-many list fields (Category[] on both sides) don't generate the hidden join table yet, that's on the roadmap, and the docs say so honestly.

Is this a replacement for prisma db seed?

It complements it: prisma db seed runs your hand-written script, SeedBase generates the dataset so you don't have to write one, useful when the schema is large or non-TypeScript services share the database.

I used @snaplet/seed and createSeedClient. Can I switch?

Yes. SeedBase reads the same schema.prisma you already have, so you remove @snaplet/seed and wire seedPrisma in its place, no schema rewrite. The full migration walkthrough is on the Snaplet Seed alternative page.

Two minutes to a fully populated database

Sign up, import your schema, generate. No sales call, no credit card, the free tier is enough for a real first impression.

  • FK-consistent
  • Realistic distributions
  • SQL / CSV / JSON
  • EU-hosted
Start free

Other stacks: Django test data · SQL test data  ·  Compare: Snaplet Seed alternative · vs Faker  ·  Docs