NestJSData with an ORMLesson 48 / 69

Seeding data

Exercise25 min

Seeding data

A seed makes a database born useful — tables arrive with realistic content:

const result = await seeder.seed(FULLSTACK_ROADMAP);
// Seeded roadmap "fullstack": 7 courses, 24 chapters, 69 lessons.

The seeder in this repo demonstrates three production habits worth stealing:

  • Idempotent — run it twice, get the same database.
  • Transactional — a failure rolls back to before it started.
  • Guarded — it refuses to destroy learner data on re-seed.

npm run seed:roadmap is the one command that turns an empty database into this entire app's content.

Exercise

Read src/database/seeds/roadmap.seeder.ts and find the three habits in the code. Then design a seed for books + authors.

Practice in the diagram lab

This lesson's practice belongs in the diagram editor — design the schema you just read about, grade it against the solution, and save it to your account.

Open the diagram lab