Skip to main content

Class: SeedRunner

Defined in: src/seeding/SeedRunner.ts:51

Tracks and executes structured seed modules, preventing double-execution via a __entityts_seeds table.

Models the same pattern as MigrationRunner for consistency.

Example​

import * as seed1 from './seeds/001_roles';
import * as seed2 from './seeds/002_default_users';

const runner = new SeedRunner(context.adapter);
const { applied } = await runner.run([seed1, seed2]);
console.log('Seeds applied:', applied);

Constructors​

Constructor​

new SeedRunner(adapter): SeedRunner

Defined in: src/seeding/SeedRunner.ts:54

Parameters​

ParameterType
adapterIDbAdapter

Returns​

SeedRunner

Methods​

ensureSeedsTable()​

ensureSeedsTable(): Promise<void>

Defined in: src/seeding/SeedRunner.ts:59

Creates the __entityts_seeds tracking table if it doesn't exist.

Returns​

Promise<void>


getAppliedSeeds()​

getAppliedSeeds(): Promise<SeedRecord[]>

Defined in: src/seeding/SeedRunner.ts:72

Returns all seed records that have been applied to the database.

Returns​

Promise<SeedRecord[]>


run()​

run(seeds): Promise<{ applied: string[]; }>

Defined in: src/seeding/SeedRunner.ts:85

Runs all pending seed modules that have not yet been applied.

Parameters​

ParameterTypeDescription
seedsSeedModule[]Ordered list of seed modules to execute.

Returns​

Promise<{ applied: string[]; }>

An object containing the names of seeds applied in this run.


status()​

status(seeds): Promise<SeedStatus[]>

Defined in: src/seeding/SeedRunner.ts:136

Returns the applied/pending status of each seed module.

Parameters​

ParameterTypeDescription
seedsSeedModule[]The full list of seed modules in dependency order.

Returns​

Promise<SeedStatus[]>

An array of SeedStatus objects indicating which seeds have been applied.

Example​

const statuses = await runner.status([seed1, seed2]);
statuses.forEach(s => console.log(s.name, s.applied ? '✅' : '⏳'));

reset()​

reset(): Promise<void>

Defined in: src/seeding/SeedRunner.ts:158

Clears all entries from the __entityts_seeds tracking table, allowing all seeds to be re-run.

Warning: This does NOT undo the data changes made by the seeds — it only resets the tracking table. Use only in development/test environments.

Returns​

Promise<void>