prisma seed database

Seed your database with Prisma and Snaplet

Prisma brings the structure, Snaplet seeds the data.

Need data for your database? Whether you’re setting up a test to validate a feature, or preparing a new development environment from scratch, seeding your database can often feel like a chore.

If you’re a Prisma user though, Prisma’s integrated seeding functionality combined with Snaplet makes seeding your database a breeze!

Prisma Migrate x Snaplet Restore

Prisma, with its intuitive approach to database migrations, is already a favorite tool for many developers. It simplifies database schema changes, making them more manageable and less error-prone. Now, combine this with Snaplet, and you have a powerhouse duo that not only structures your database efficiently but also populates it with data that mirrors your production environment.

There’s two moving parts:

  1. Prisma Migrations: Prisma Migrate auto-generates SQL migrations from your Prisma schema, so you don’t need to write the SQL by hand. These migration files are fully customizable, giving you full control and ultimate flexibility — from local development to production environments..
  2. Snaplet Restore: This is where Snaplet steps in. Once you have your schema set up, Snaplet takes over to fill your database with realistic, yet safe, data. No need to write a cumbersome seed script.

The process is straightforward:

  • Run prisma migrate dev to get your database schema up to speed.
  • Use snaplet restore --data-only to pump in the data, giving you a development environment that mirrors real-world complexities without any of the risks.

Use cases

  1. Rapid Development Cycles: For those who iterate fast, this integration means less time fiddling with data and more time building features.
  2. New Developer Onboarding: New team member? Get them up and running with a database that reflects the current state of your production, minus the sensitive data.
  3. Testing Complex Interactions: Testing complex user interactions or data relationships? Realistic data helps you catch those edge cases early.
  4. Demonstrations and Prototypes: Need to showcase your project? Use data that tells the real story of how your application works.

Further reading

Need more information? Check out the Prisma recipe in our documentation, or come chat to us on Discord if you need help!

Jian Reis
January 24, 2022