Skip to main content

Prisma Seed

Prisma Migrations creates the database structure, and Snaplet restores the data.

prisma migrate devsnaplet restore --data-only

If you don't want to run two commands, you can automatically seed the database with data, after running prisma migrate reset or prisma migrate dev, by adding the following to your package.json file.

"prisma": {  "seed": "snaplet restore --data-only --no-backup"}

Learn "how to seed your database in Prisma" from their documentation.

Limitations to consider#

There are a few things to keep in mind when running this feature:

  1. Backwards incompatible table changes will result in no data being restored for the entire table. Backwards incompatible changes include but aren’t limited to: removed columns or newly added columns that do not have any default values. The result of attempting a restoration with the --data-only flag, given the above changes will result in an empty table.
  2. Under the hood, Snaplet relies on CREATE DATABASE ... WITH TEMPLATE for cloning the current database as part of the restoration, even though we subsequently clear the tables. We do this so we can preserve the original table IDs. This implementation detail may cause performance issues for large databases. If you do experience any performance issues, please reach out and let us know.
  3. Any previous data will be cleared from each table that exists in the snapshot – this will occur in a cascading fashion where related rows in other tables will also be cleared. Any rows in tables added since the last snapshot will be kept as is, with the exception of rows with relations to data in the snapshot tables that are cleared – those will be cleared too. Bare in mind that you are able to opt for a backup of your existing database (of which is currently true by default) .
  4. If any tables were removed since the last snapshot, the rest of the restoration will continue.
  5. Any failed database operations that occurred during the restoration (e.g. the removal of a table) will be logged to the restore.log and the first three log entries will be show in the console.