0
0
Supabasecloud~30 mins

Seed data management in Supabase - Mini Project: Build & Apply

Choose your learning style9 modes available
Seed Data Management with Supabase
📖 Scenario: You are setting up a new Supabase project for a small online bookstore. To get started, you need to add some initial books data into your database so the app can display books right away.
🎯 Goal: Create seed data for the books table in Supabase, configure a helper variable for batch insertion, write the main logic to insert the seed data, and finalize the seed script for deployment.
📋 What You'll Learn
Create a list of book records with exact fields and values
Add a configuration variable for batch size
Write the insertion logic using Supabase client
Complete the seed script with proper export and async function
💡 Why This Matters
🌍 Real World
Seeding initial data is a common step when setting up new cloud databases to have ready-to-use content for development or demos.
💼 Career
Knowing how to manage seed data with Supabase is useful for backend developers and cloud engineers working with modern serverless databases.
Progress0 / 4 steps
1
Create the initial seed data array
Create a constant called books that is an array of objects. Each object must have these exact fields and values:
{ id: 1, title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', year: 1925 },
{ id: 2, title: '1984', author: 'George Orwell', year: 1949 },
and { id: 3, title: 'To Kill a Mockingbird', author: 'Harper Lee', year: 1960 }.
Supabase
Hint

Use const books = [ ... ] and include exactly three objects with the given fields and values.

2
Add a batch size configuration variable
Create a constant called BATCH_SIZE and set it to 3 to control how many records to insert at once.
Supabase
Hint

Use const BATCH_SIZE = 3; exactly as shown.

3
Write the seed insertion logic
Write an async function called seedBooks that uses the Supabase client supabase to insert the books array into the books table using supabase.from('books').insert(books). Await the insertion call.
Supabase
Hint

Define async function seedBooks() and inside it call await supabase.from('books').insert(books);

4
Complete the seed script for deployment
Export the seedBooks function as the default export using export default seedBooks;.
Supabase
Hint

Use export default seedBooks; exactly as shown to complete the seed script.