[Proposal] Seed feature #8333
emulienfou
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Loopback allow by default (using lb4-cli) to migrate database schema.
However, there is no script provided by default to seed database.
The current solution I found was this custom script: https://stackoverflow.com/a/54796872
Proposition
The idea would be to integrate by default (same as the migrate script) a feature to seed database depending on multiple sources of data (json files, manually create using repository create, ...).
Code
Here is an code I made using a custom Mixin, based on the idea of the next stackoverflow: Loopback 4: Create seeders to add dummy data in mySQL table.
The mixin
Application
This mixin needs to be implemented in the Application class as follow:
Seed script
The seed script located in:
src/seed.ts
Updating package.json
Last step would be to declare the new seed script as follow:
Beta Was this translation helpful? Give feedback.
All reactions