Seeding test data
So far, we've built database entities that let TypeORM construct SQL tables. Let's now enter some information into the database. You could do this manually, but it would be exhausting; we need to automate it sufficiently so that we can have it up and running quickly.
We can accomplish this by utilizing the typeorm-seeding
package to create factories and seeders for our entities, which simplifies the process. Perform the following steps:
- Return to your Terminal and begin by installing the package with the following command:
npm install typeorm-seeding
- Install the type definitions of the Faker library and create the
src/database/
,database/seeds/
, anddatabase/factories/
folders:npm install -D @types/faker cd src/ && mkdir database cd database && mkdir seeds factories
- Add the following scripts to the
package.json
file to invoke the seed commands:"scripts": { "seed:config": "ts-node ./node_modules...