EPIC: re-design of `db seed` feature
See original GitHub issueprisma 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 https://github.com/prisma/prisma/pull/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 https://github.com/prisma/prisma/pull/8146
- QA db seed
- Update docs https://github.com/prisma/docs/pull/2161
- https://github.com/prisma/prisma/issues/8033
- e2e https://github.com/prisma/e2e-tests/issues/1806
- Update https://github.com/prisma/prisma/issues/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"topic%3A+db+seed"+is%3Aopen
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5 (4 by maintainers)
Top GitHub Comments
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.
Note this will work and is cleaner IMO: