ISeed, registered with @decorator.seed(). The decorator adds the class to the container and to the seeds registry, so the runner can resolve, filter, and order it. run() populates the database, and the other members decide whether — and when — it runs.
Scaffold a seed
Generate a seed with the CLI.talos seed:create writes a seed class under modules/<module>/src/seeds/, an accompanying .yml data file, and a matching test under modules/<module>/tests/seeds/, then regenerates the seeds.ts barrel export and creates the module’s bin/seed/run.ts runner if it is missing.
| Option | Description | Default |
|---|---|---|
--name | Name of the seed. Normalized to PascalCase with a Seed suffix. | Prompted if omitted |
--module | Module the seed is created in. | shared |
.yml file and is ready to fill in:
seed:create command for the full reference.
Implement run()
Fill in run() with the inserts that populate the database. Keep the records in the sibling .yml file and import them, so data stays separate from logic. Whatever run() returns is passed to any seed that depends on this one, so return the records a dependent seed needs to reference.
Gate the seed
Three members decide whether the seed runs:isActive()— returnfalseto skip the seed entirely. Use it to disable a seed without deleting it.getEnv()— return the environments the seed targets (for example[Environment.Development, Environment.Test]). An empty list runs in every environment; a non-empty list runs only when the currentAPP_ENVis included.getDependencies()— return the seed classes that must run first. Each dependency is resolved from the container and run before this seed, and its return value is passed into this seed’srun(data).
Next steps
- Running seeds: populate the database with
talos seed:run. - Caching: how a seed’s run is cached and invalidated.