Framework
Seed a Next.js + Supabase App with Realistic Test Data
The Setup
You have a Next.js App Router project with a Supabase Postgres backend. You want 100 users, 500 posts, and 2,000 comments that are relationally consistent — locally and in CI.
Seed Script
// scripts/seed.ts
import { createClient } from "@supabase/supabase-js";
const supabase = createClient(
process.env.SUPABASE_URL!,
process.env.SUPABASE_SERVICE_ROLE_KEY!
);
const res = await fetch("https://api.mockhero.dev/api/v1/generate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": process.env.MOCKHERO_API_KEY!,
},
body: JSON.stringify({
seed: 42,
tables: [
{ name: "profiles", count: 100, fields: [
{ name: "id", type: "uuid" },
{ name: "full_name", type: "full_name" },
{ name: "email", type: "email" }
]},
{ name: "posts", count: 500, fields: [
{ name: "id", type: "uuid" },
{ name: "user_id", type: "ref", ref: "profiles.id" },
{ name: "title", type: "sentence" },
{ name: "body", type: "paragraphs" }
]},
{ name: "comments", count: 2000, fields: [
{ name: "id", type: "uuid" },
{ name: "post_id", type: "ref", ref: "posts.id" },
{ name: "author_id", type: "ref", ref: "profiles.id" },
{ name: "body", type: "paragraph" }
]}
]
})
});
const data = await res.json();
await supabase.from("profiles").insert(data.profiles);
await supabase.from("posts").insert(data.posts);
await supabase.from("comments").insert(data.comments);
RLS Note
Use the service-role key in the seed script — anon key inserts will be blocked by RLS. Never ship the service-role key to the browser.
Run It
npx tsx scripts/seed.ts
Why This Is Better Than Manual INSERTs
- Foreign keys wired automatically via
ref. - Deterministic — same
seedgives identical data on every run. - One file, readable in code review.
Get Started
Sign up free and drop this script into your Next.js repo.
M
MockHero Team
Guides and tutorials for generating realistic test data with the MockHero API.
Start generating test data for free
1,000 rows/month on the free tier. No credit card required.
Get Your API Key