Running seeds
The options each seed command takes, the dry run that rolls itself back, the config key that seeds on startup, and the same four operations from code.
questpie seed is one of three ways to reach the runner. A deploy step calls
the CLI, an app can seed itself as it boots, and a test suite calls the same
operations from code.
Options
| Option | Commands | Effect |
|---|---|---|
-c, --config <path> | all four | Use a config file other than questpie.config.ts. |
--category <categories> | seed, seed:undo | Comma-separated filter: required, dev, test. |
--only <ids> | seed, seed:undo, seed:reset | Comma-separated seed ids. |
-f, --force | seed | Run them again even though tracking says they finished. |
--validate | seed | Run them in a transaction, then roll it back. |
--force on a checkpointed seed clears its step checkpoints and its tracking
row first, so every step runs again.
The dry run
questpie seed --validate wraps the whole selected batch in one transaction,
runs it, then throws the transaction away. Rows and step checkpoints go with it,
no tracking row is ever written, and the seeds stay pending. It answers whether
the code runs against the schema you have now.
Only the database rolls back
Email, HTTP calls, queue jobs and object-storage writes are outside the transaction and happen for real. Keep those out of a seed you plan to validate, or guard them yourself.
On startup
autoSeed in your runtime config runs seeds as the app boots, after migrations
when autoMigrate is on too.
import { runtimeConfig } from "questpie/app";
export default runtimeConfig({
autoSeed: "required",
});A single category is a shorthand that includes required, because demo and test
data is worth nothing without the bootstrap rows underneath it. An array is
taken literally.
| Value | Runs |
|---|---|
true | every pending seed |
"required" | required |
"dev" | required, dev |
"test" | required, test |
["dev"] | dev, no required |
false or omitted | nothing |
Startup seeding is a background promise. await app.waitForInit() resolves once
migrations and seeds have finished, which is the line to put before you start
serving traffic.
From code
app.seeds exposes the four operations with the same options the CLI parses.
Tests and one-off scripts use it instead of shelling out.
await app.seeds.run({ category: "test" });
await app.seeds.run({ only: ["demoPosts"], force: true });
const { pending, executed } = await app.seeds.status();
await app.seeds.undo({ category: "dev" });
await app.seeds.reset({ only: ["demoPosts"] });run() takes validate too. The runner logs to stdout unless
QUESTPIE_SEEDS_SILENT is 1, true or yes. NODE_ENV=test silences it on
its own.
What the CLI does and the API does not
After questpie seed finishes, the CLI reindexes every collection that has
searchable turned on. Write-time indexing normally goes through the queue, and
the CLI has no worker running, so the seeded rows would otherwise stay invisible
to search until the next reindex.
Related
- Seeds for the file, the categories and the ordering.
- Checkpointed seeds for what
--forceclears. - Configuration for the rest of
runtimeConfig.
Checkpointed seeds
seed.steps() trades one transaction for a checkpoint per step, so a seed that fails on its two hundredth upload resumes there instead of starting over.
Eligible fields
A merge has to produce a value the field would have accepted anyway. That rules out most of the field builder, and the app names every reason it rejected yours.