Skip to content

CLI

The package ships a CLI binary so you can run seeders or seed entities directly from the terminal without writing a seed script.

TypeScript

To use .ts files directly, install ts-node as a dev dependency and the CLI will pick it up automatically. Compiled .js files work without it.

seed:run

Loads all @Seeder-decorated classes from a glob pattern and runs them in topological order.

Pass --dry-run (-n) to see which seeders would run without executing them or touching the database:

bash
npx @joakimbugge/mikroorm-seeder seed:run './src/seeders/*.ts' -o ./src/orm.ts
bash
yarn @joakimbugge/mikroorm-seeder seed:run './src/seeders/*.ts' -o ./src/orm.ts
bash
pnpm exec @joakimbugge/mikroorm-seeder seed:run './src/seeders/*.ts' -o ./src/orm.ts
bash
npx @joakimbugge/mikroorm-seeder seed:run './src/seeders/*.ts' --dry-run
# Dry run — seeders will not run
#
# 3 seeders found:
#   UserSeeder
#   PostSeeder
#   CommentSeeder

seed:entities

Loads entity constructors from a glob pattern, filters to those with at least one @Seed decorator, and persists --count instances of each (default: 1).

Pass --dry-run (-n) to create entities in memory and print them without writing to the database:

bash
npx @joakimbugge/mikroorm-seeder seed:entities './src/entities/*.ts' -o ./src/orm.ts --count 20
bash
yarn @joakimbugge/mikroorm-seeder seed:entities './src/entities/*.ts' -o ./src/orm.ts --count 20
bash
pnpm exec @joakimbugge/mikroorm-seeder seed:entities './src/entities/*.ts' -o ./src/orm.ts --count 20
bash
npx @joakimbugge/mikroorm-seeder seed:entities './src/entities/*.ts' --dry-run --count 3
# Dry run — nothing will be written to the database
#
# 3 × User
# User { name: 'Alice Smith', email: 'alice@example.com', age: 27 }
# User { name: 'Bob Jones', email: 'bob@example.com', age: 34 }
# User { name: 'Carol White', email: 'carol@example.com', age: 22 }

seed:list

Prints all seeder runs recorded in the history table:

bash
npx @joakimbugge/mikroorm-seeder seed:list -o ./src/orm.ts
bash
yarn @joakimbugge/mikroorm-seeder seed:list -o ./src/orm.ts
bash
pnpm exec @joakimbugge/mikroorm-seeder seed:list -o ./src/orm.ts
┌─────────┬─────────────────────┬──────────────────────────────┐
│ (index) │ name                │ executed_at                  │
├─────────┼─────────────────────┼──────────────────────────────┤
│ 0       │ 'UserSeeder'        │ '2026-04-01T10:00:00.000Z'   │
│ 1       │ 'PostSeeder'        │ '2026-04-01T10:00:01.243Z'   │
└─────────┴─────────────────────┴──────────────────────────────┘

If the history table does not exist yet, or no seeders have run, a descriptive message is printed instead. Pass --table (-t) if you use a custom historyTableName.

seed:untrack

Removes a seeder from the history table so it runs again on the next application boot:

bash
npx @joakimbugge/mikroorm-seeder seed:untrack UserSeeder -o ./src/orm.ts
bash
yarn @joakimbugge/mikroorm-seeder seed:untrack UserSeeder -o ./src/orm.ts
bash
pnpm exec @joakimbugge/mikroorm-seeder seed:untrack UserSeeder -o ./src/orm.ts

If your NestJS module uses a custom historyTableName, pass --table (-t) to match:

bash
npx @joakimbugge/mikroorm-seeder seed:untrack UserSeeder -o ./src/orm.ts --table seed_history

npm scripts

A common pattern is to define scripts in package.json with the paths baked in:

json
{
  "scripts": {
    "seed:run": "mikroorm-seeder seed:run './src/seeders/*.ts' -o ./src/orm.ts",
    "seed:entities": "mikroorm-seeder seed:entities './src/entities/*.ts' -o ./src/orm.ts"
  }
}

Run them with your package manager:

bash
npm run seed:run
bash
yarn seed:run
bash
pnpm seed:run

To pass extra arguments at call time, npm and pnpm require a -- separator before any flags; yarn does not:

bash
npm run seed:entities -- --count 50
bash
yarn seed:entities --count 50
bash
pnpm seed:entities -- --count 50

MikroORM instance

Pass --orm (-o) with a path to a file that exports a MikroORM instance:

ts
// orm.ts
import { MikroORM } from '@mikro-orm/core'

export default await MikroORM.init({ ... })

If the flag is omitted the CLI looks for mikroorm-seeder.config.ts then mikroorm-seeder.config.js in the current working directory.

TIP

Wrap glob patterns in single quotes to prevent your shell from expanding them before they reach the CLI. Without quotes, the shell resolves the glob and the CLI receives a list of individual file paths — which also works, but prevents the CLI from using tinyglobby's pattern matching.

Released under the MIT License.