feat(seed): seed demo data on a new account's first visit (PMS-157) #146
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/pms-157-new-account-seeding"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Seeds a small set of illustrative rows into a brand-new account on its first authenticated visit (PMS-157), so a fresh account demonstrates how Mokosh works instead of showing an empty shell. Demo set: one company, two contacts, three tickets, inserted through the real
ContactService/TicketServicecreate paths (validation, FK checks, and audit rows all apply).How it triggers
New
seedmodule with a middleware (seed_middleware) added inner of the auth middleware. Auth populatesAuthState; this layer then reads the resolved tenant/user and spawnsSeedService::ensure_demo_seededdetached, so seeding never adds latency to the triggering request and any failure is logged and swallowed (it can never break a request).Lazy first-visit was chosen over hooking
TenantService::create_tenantbecause Bunyip users JIT-land in a pre-existing tenant and never pass through tenant creation.Idempotency (three guards)
tenants.settings->>'demo_seeded': claims the seed exactly once, even under a burst of concurrent first requests (only the request that flips the flag proceeds).Kill-switch
Set
MOKOSH_DEMO_SEED=falseto disable, e.g. for E2E/staging that run against the shared default tenant.Tests
tests/seed_demo.rscovers the happy path (one company, two contacts, three tickets, flag set), cross-process idempotency (a fresh service does not re-seed), and the emptiness guard (a tenant with existing data gets the flag but no demo rows).cargo check --all-targets,clippy --all-targets, andfmt --checkare clean; integration tests run in CI.#PMS-157
🤖 Generated with Claude Code