How to reset and seed a Prisma database
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Prisma is an open-source database toolkit that simplifies database workflows, making them more efficient and type-safe.
One of the common tasks during development is to reset your database and seed it with initial data, especially when you’re setting up the development environment or testing your application. In this post, we’ll walk you through how to do this with Prisma.
When you want to revert your database to its initial state or apply new changes to the Prisma schema, you might need to reset it. Here’s how:
npx prisma migrate reset
This will:
Seeding allows you to populate your database with predefined data. Here’s how to set up and run seeding with Prisma:
Create a new file named seed.ts (for TypeScript) or seed.js (for JavaScript) inside the prisma folder.
This file should export a function named seed that will handle the seeding logic. Here’s an example using TypeScript:
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function seed() {
await prisma.user.create({
data: {
name: 'John Doe',
email: '[email protected]',
},
});
}
seed()
.catch((error) => {
console.error(error);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
In your schema.prisma file, you’ll need to tell Prisma about your seed script. Modify the generator block to include a seed field:
generator client {
provider = "prisma-client-js"
seed = "prisma/seed.ts" // or seed.js if you're using JavaScript
}
With everything in place, you can now seed your database with the following command:
npx prisma db seed
Prisma will execute the seed script, and your database will be populated with the data you’ve defined.
For Prisma workflows, Basedash works as an AI-native BI layer over your database so engineers and non-technical teammates can inspect migration outcomes, ask follow-up questions, and track changes in shared dashboards.
With Prisma’s streamlined CLI and the seeding setup, you can make sure your development environment is always in a consistent state. Remember to exercise caution when resetting databases, especially in production environments, to avoid any unintended data loss.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.