Prisma
This example shows how to set up your Seed workflow with Prisma (opens in a new tab).
Prerequisites
- Set up a new Prisma project by following the Prisma Quickstart (opens in a new tab) guide.
1. Install Seed
Set up Seed in your Prisma project by running the following command:
2. Configure Seed
Using the previous command should have created a seed.config.ts
configuration file.
You can use it as is, or customize it to fit your needs.
3. Customize the Seed Script
The npx @snaplet/seed init
command should also have created a seed script example seed.mts
.
You can move this file into your prisma
directory and customize it to seed your database with the data you need.
4. Hook into Prisma seeding workflow
You can hook into Prisma seeding workflow (opens in a new tab) by specifying a seed
command in your package.json
file:
With this change, the database will be seeded with the data you specified in your seed.mts
file for each of the following commands:
prisma db seed
prisma migrate dev
prisma migrate reset
5. Keep Seed Client in sync with your database
Whenever your database structure changes (e.g after a new migration is applied), @snaplet/seed
will need be regenerated to reflect the new structure. To do this, run the following command:
If you want to automate this process, you can add a post script (opens in a new tab) to your package.json
file: