How to Seed Supabase with Realistic Test Data
The Problem
Every Supabase project starts the same way: you create beautiful tables, define RLS policies, and then sit there staring at an empty database. Writing manual INSERT statements is tedious, and tools like Faker.js require you to build an entire seed script from scratch, handle relational foreign keys yourself, and hope the data looks realistic enough for demos.
If you are working with a team, the problem multiplies. Everyone ends up with a different local dataset, QA tests against stale fixtures, and staging environments look nothing like production.
The Solution: MockHero API
MockHero is a single API call that returns realistic, relationally-consistent test data. Define your schema with 156+ field types, add ref fields to connect tables, and get back JSON you can pipe directly into Supabase. No libraries to install, no generators to maintain.
Quick Setup
curl -X POST https://api.mockhero.dev/api/v1/generate \
-H "x-api-key: mh_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"tables": [
{
"name": "profiles",
"count": 10,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "full_name", "type": "full_name" },
{ "name": "email", "type": "email" },
{ "name": "avatar_url", "type": "avatar_url" },
{ "name": "created_at", "type": "datetime" }
]
},
{
"name": "posts",
"count": 30,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "author_id", "type": "ref", "params": { "ref": "profiles.id" } },
{ "name": "title", "type": "sentence" },
{ "name": "body", "type": "paragraphs" },
{ "name": "published", "type": "boolean" }
]
}
],
"format": "json"
}'
Step-by-Step Guide
1. Install dependencies
npm install @supabase/supabase-js
2. Get your MockHero API key
Sign up at mockhero.dev/sign-up and copy your API key from the dashboard. The free tier gives you 1,000 rows per month.
3. Write the seed script
Create a file called seed.mjs in your project root:
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: {
"x-api-key": process.env.MOCKHERO_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
tables: [
{
name: "profiles",
count: 20,
fields: [
{ name: "id", type: "uuid" },
{ name: "full_name", type: "full_name" },
{ name: "email", type: "email" },
{ name: "avatar_url", type: "avatar_url" },
{ name: "created_at", type: "datetime" },
],
},
{
name: "posts",
count: 50,
fields: [
{ name: "id", type: "uuid" },
{ name: "author_id", type: "ref", params: { ref: "profiles.id" } },
{ name: "title", type: "sentence" },
{ name: "body", type: "paragraphs" },
{ name: "published", type: "boolean" },
],
},
],
format: "json",
}),
});
const { data } = await res.json();
const { error: profilesError } = await supabase
.from("profiles")
.insert(data.profiles);
if (profilesError) console.error("Profiles error:", profilesError);
const { error: postsError } = await supabase
.from("posts")
.insert(data.posts);
if (postsError) console.error("Posts error:", postsError);
console.log(
"Seeded", data.profiles.length, "profiles and",
data.posts.length, "posts"
);
4. Run the script
node seed.mjs
5. Verify in Supabase Studio
Open the Table Editor in your Supabase dashboard. You should see 20 profiles and 50 posts, each post correctly referencing a profile through the author_id foreign key.
Complete Example
The seed script above is complete and production-ready. For larger datasets, increase the count values and consider batching your Supabase inserts. MockHero handles the relational consistency automatically so every author_id maps to a real profiles.id.
Why MockHero vs Faker / Manual Seeds
- Relational data out of the box —
reffields guarantee foreign keys match across tables, no manual wiring. - No code to maintain — your seed logic is a JSON schema, not hundreds of lines of JavaScript.
- Deterministic seeds — pass a
seedparameter to get the same data every time, great for CI.
Get Started
MockHero offers a free tier with 1,000 rows per month, no credit card required. Sign up here and start seeding your Supabase project in under a minute.
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