MasterRecord

Seeding

Ship reference and demo data alongside your schema.

Seeds let you insert initial data — admin users, lookup tables, demo content — as part of your migration flow. Seeds are idempotent: re-running them won’t create duplicates.

Declaring a seed on a dbset#

Attach .seed() when you register an entity in the context:

AppContext.js
class AppContext extends context {
  constructor() {
    super();
    this.env('config/environments');

    this.dbset(Role).seed([
      { id: 1, name: 'admin' },
      { id: 2, name: 'editor' },
      { id: 3, name: 'viewer' },
    ]);

    this.dbset(User).seed({ name: 'Admin', email: 'admin@example.com', role_id: 1 });
  }
}

Seeding inside a migration#

You can also insert, update, or delete seed rows directly in a migration’s up():

migration
async up(table) {
  await this.init(table);
  await this.createTable(table.Role);
  await this.insertSeedData('roles', [
    { id: 1, name: 'admin' },
    { id: 2, name: 'editor' },
  ]);
}
Tip
Seeds run when you apply migrations (master db migrate). Because they upsert by primary key, they’re safe to keep in every environment — development, CI, and production.