Repository navigation
Description
prisma db seed is currently a Preview feature.
During this phase, we noticed different issues caused by the complexity of the current implementation.
The Migrations Team decided to remove the complexity and make it a lot easier to understand for users and to maintain.
The new implementation is in #8146
How it will work is that a prisma.seed property in the package.json of your project will be required if you want to use prisma db seed.
The CLI will give examples that can be copy-pasted.
If you are currently using the previous implementation of prisma db seed and upgrade to this new version then it will throw an error with an upgrade help message which should be easy to fix (add prisma.seed to the package.json)
package.json example for a JavaScript project
"prisma": {
"seed": "node prisma/seed.js"
} package.json example for a TypeScript project
"prisma": {
"seed": "ts-node prisma/seed.ts"
}Example of a prisma/seed.js
async function main() {
await new Promise((resolve) => setTimeout(resolve, 100))
console.log('Hello from seed.js')
}
main()
.then(() => console.log('Goodbye from seed.js'))
.catch((e) => {
console.error(e)
process.exit(1)
})What needs to done for releasing the "new" db seed:
- Review and merge fix(db seed): redesign of db seed #8146
- QA db seed
- Update docs
db seedGA web#2161 -
db seedtests need to run on multiple platforms, not just Ubuntu #8033 - e2e Test seeding ecosystem-tests#1806
- Update Preview feature feedback: Integrated seeding #5161
- Close issues and let users know that they can use the new version https://github.com/prisma/prisma/issues?q=is%3Aissue+label%3A%22topic%3A+db+seed%22+is%3Aopen
Activity
Jolg42 commentedon Aug 13, 2021
It's possible to try it out with a specific version of the Prisma CLI like this:
Or by using npx with the specific version:
jasonkuhrt commentedon Aug 13, 2021
Note this will work and is cleaner IMO:
tobiasdiez commentedon Aug 21, 2021
May I suggest that the error handling part (copied from the above example)
may be moved to Prisma's cli code, i.e one only exports the
mainmethod and prisma takes care of the invocation. The main reason is that sometimes you do not want to exit in case there is an error during seeding. For example, if one usesgenerate --watchorjest --watchusingseedto initialize tests. In the former case you prefer to be notified about the error, and in the latter the test should fail -- however, you don't really want to exit the calling process.Jolg42 commentedon Aug 24, 2021
Hi @tobiasdiez indeed, exiting is not the best in some cases. This is just an example and in this implementation you are free to change it as you need.
We removed the "magic" around export and invocation to simplify but that also means you can write a small layer that does that in your project.
Jolg42 commentedon Sep 7, 2021
Closing, rest is tracked in #8628
I'll create an issue to have better suggestion for ESM module projects help output.