Skip to content
Auto
English

Seeding

tapedb ships no data of its own. What a realistic row looks like is a convention of your domain, and a library that guesses it is wrong everywhere but the place it was written. What it ships is the runner, so a seeder is a short file of plain TypeScript rather than an insertion script.

tapedb.seed.ts
import { defineSeeder } from "@tapedb/tapedb/seed";
import type app from "./tapedb.schema";
export default defineSeeder<typeof app.models>(async ({ ctx }) => {
const projects = await ctx.create("project", 6, (rng) => ({
name: ctx.unique("project", "name", (r) => `Project ${r.int(1, 1000)}`),
archived: rng.int(0, 9) === 0,
}));
await ctx.create("task", 60, (rng) => ({
projectId: ctx.ref(projects),
title: rng.pick(["Draft", "Review", "Ship"]),
done: rng.int(0, 9) < 4,
}));
});

ctx carries create, insert, listIds, ref, unique, clear, model, rng, rngFor and written.

Terminal window
npx tapedb-cli seed --workspace <uuid> # against `tapedb dev`
npx tapedb-cli seed --workspace <uuid> --dry-run # check the rows, write none
npx tapedb-cli seed --workspace <uuid> --seed lab # the same rows every time

The same seed writes the same rows, and rngFor(label) gives a stream that depends only on its label, so a row keeps its values whatever else the run did first. Rows go through the engine’s own routes in batches of 500, so access rules, the tape and the history see them exactly as they see a client’s writes. Declared defaults are filled in, because the engine wants every column named. A personal() field is refused: seeded personal data has to go through the app’s own write path, which owns the encryption key.

Dates are the one thing a seed cannot pin on its own. rng.past() measures from now, so pass from when the same seed has to give the same dates tomorrow. The engine’s createdAt, updatedAt and updatedSeq are written at insert, so they differ between runs whatever the seed.

Next: migrations, or files, presence and broadcast.