Skip to content

F12: Demo seed data — Seed:Demo flag (#58) - #63

Merged
mforce merged 4 commits into
mainfrom
feat/f12-demo-seed
Jul 18, 2026
Merged

mforce merged 4 commits into
mainfrom
feat/f12-demo-seed

Conversation

@mforce

@mforce mforce commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Closes #58. After a dev-DB wipe, Seed__Demo=true boots a fully populated app instead of empty screens.

What

DemoDataSeeder — own startup scope, resolves the TenantContext to the seeded account, and drives the real handlers (record → submit → lots/movements, customer → order → items → FIFO confirm), so every downstream fact exists exactly as if a user clicked it in. Deterministic quantities — reproducible demos, no Random.

Seeds: two active flocks (45wk/20wk) + a depleted 2025 batch with a backdated 430-bird end-of-lay cull; a week of submitted graded entries per active flock with losses and sprinkled mortality (today = Draft for one flock, unrecorded for the other, so the dashboard shows both states and the "no entry" flag); three customers; one confirmed order + one open draft.

Safety

  • Default false — the flag must be explicitly set (Seed__Demo=true in deploy/.env or user-secrets); prod can't accidentally get fake data.
  • Gated on an empty flock catalog: runs once on a fresh DB, no-op afterwards, never resurrects deleted data.
  • Best-effort: failure logs and continues; the app starts regardless.

Tests (+1 → 124)

Derived test host (runtime-generated credentials) on a fresh catalog: 3 flocks incl. depleted with ledger-reduced count (450−430=20), stock > 0, confirmed + draft orders, 14+ entries; second startup no-op. Guard also verified live against the populated dev DB ("Demo seed skipped: flocks already exist").

mforce added 2 commits July 17, 2026 17:28
A dev-DB wipe left every screen empty until data was re-clicked by
hand. With Seed__Demo=true (default false — prod can never
accidentally get fake data) a fresh database boots with:

- Three flocks: 45wk + 20wk active layers and a depleted 2025 batch
  (backdated depletion via the domain so historical rules hold).
- A week of submitted daily entries per active flock with graded
  production, losses, and sprinkled mortality — today left as a Draft
  for one flock and unrecorded for the other, so both entry states
  and the dashboard "no entry" flag show.
- A 430-bird end-of-lay cull on the depleted flock.
- Three customers; one confirmed order (FIFO allocation exercised)
  and one open draft.

DemoDataSeeder runs in its own startup scope, resolves the
TenantContext to the seeded account, and drives the real handlers —
lots, stock, movements, and allocation exist exactly as if clicked
in. Gated on an empty flock catalog: runs once on a fresh DB, no-op
afterwards, never resurrects deleted data. Best-effort like the main
seeder (failure logs and continues).

Deterministic quantities (no Random) so demos are reproducible.

Test (+1 -> 124): derived host with Seed:Demo + runtime-generated
credentials on a fresh catalog — every read surface populated (3
flocks incl. depleted with ledger-reduced counts, stock > 0,
confirmed + draft orders, 14+ entries); second startup is a no-op.
Guard also verified against the populated dev DB: "Demo seed
skipped: flocks already exist."

Closes #58
- Seed:Enabled=false now disables the demo seed too — it is documented
  as switching off ALL startup seeding, and the demo seeder previously
  ignored it. (codex P2)
- Partial-failure cleanup: the handlers commit step by step (ConfirmSale
  even opens its own transaction, so one outer transaction can't wrap
  the seed). A mid-seed failure now deletes the account's rows in the
  demo-touched tables — safe because the empty-flock guard guarantees
  everything there came from the failed run — so the next startup
  retries instead of being stuck half-seeded forever. (codex P2)

Deferred: test residue on the shared default account (tenant filters
isolate today's tests; revisit if any test ever asserts on the default
account), delete-all-flocks-triggers-reseed (dev-only flag; a wipe is
the intended reseed path).

124 tests green.
@mforce

mforce commented Jul 18, 2026

Copy link
Copy Markdown
Owner Author

Review round: codex + pi

# Source Severity Finding Action
1 codex P2 Seed:Enabled=false + Seed:Demo=true still seeded fake data — Enabled is documented as disabling all startup seeding Fixed — demo requires both flags (3cc0b86)
2 codex P2 A mid-seed failure left committed rows (handlers commit stepwise) that trip the empty-catalog guard forever — permanently half-seeded Fixed — failure cleanup deletes the account's rows in demo-touched tables; safe because the guard guarantees everything there came from the failed run. One outer transaction wasn't possible: ConfirmSale opens its own (3cc0b86)
3 pi Low Test residue on the shared default account in the collection DB Deferred — tenant filters isolate every current test; revisit if any test asserts on the default account
4 pi Med (truncated) Deleting all flocks later re-triggers the demo seed on restart Accepted — dev-only flag; a wipe is the intended reseed path, and there is no flock delete in the app
5 pi — Scope isolation, prod-safe default, guard's IgnoreQueryFilters scoping, runtime credentials Verified clean by pi

124 tests green after fixes.

pi review of the fix commit: cleanup's eight deletes were each their
own autocommit — a mid-cleanup failure could leave a half-purged,
silently inconsistent state. One transaction makes cleanup
all-or-nothing. Comment no longer claims the flock guard proves more
than it does (customers/orders are covered because DatabaseSeeder
never writes them, not by the guard).
@mforce

mforce commented Jul 18, 2026

Copy link
Copy Markdown
Owner Author

Second review round (fix-commit delta, pi)

The 3cc0b86 fix commit itself got a follow-up pi review:

Finding Verdict Action
FK delete ordering ✅ verified correct against the EF configs —
Table coverage ✅ all 8 demo-written tables purged; EggGrades correctly excluded —
Cleanup not atomic — 8 separate autocommits could half-purge Low Fixed — one transaction wraps the deletes (5c6ee56)
Safety comment overstated the flock guard's proof (customers/orders aren't flock-rooted) Low Fixed — comment now states the real reason they're safe: DatabaseSeeder never writes them (5c6ee56)
Cleanup failure swallowed (log only) Low Accepted — matches the best-effort demo stance; operator wipes manually in that corner

@mforce
mforce merged commit 5205237 into main Jul 18, 2026
3 checks passed
@mforce
mforce deleted the feat/f12-demo-seed branch July 18, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

F12: Demo seed data — Seed:Demo flag for dev/demo environments

1 participant