Seeds allow you to quickly seed the database for example for the purpose of testing. Seeds are put in the seeds folder within the project folder. There are three ways to create a seed:
- Create a JSON file with the same name as the model file. The contained JSON is added to the database with the upsertGraph method.
[
{
"username": "me",
"email": "[email protected]",
"password": "secret"
},
{
"username": "jill",
"email": "[email protected]",
"password": "secret"
}
]
- Create a js file with the same name as the model file. The function exported by this file is executed with the models as argument.
export function(models) {
const { Model1 } = models
// Do something
return jsonResult
}
- Create an arbitrarily named js file in the seeds folder and seed the model manually.
export function({ Model1, Model2 }) {
// Do something
await Model1.insertGraph(model1Data)
return Model2.insertGraph(model2Data)
}
To execute all the seeds use the commandline.
yarn db:seed