feat(data): add admin Load demo data endpoint (PMS-679) #457
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/PMS-679-load-demo-data-button"
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
Adds an admin-only
POST /api/v1/data/seed-demoendpoint that loads Mokosh's built-in demo dataset (one sample company, two contacts, three tickets) into the caller's tenant. Additive and non-destructive: it loads only into an empty tenant and never wipes.Why
Seeding the demo dataset was reachable only from the CLI (
mokosh-bootstrap qa-seed/showcase-seed) or the best-effort first-visit auto-seed. Nate asked for a UI button that works with seed data, not just ajust/CLI command, for standing up and re-populating the demo. Bunyip's admin Seed page has "Load template" buttons that populate the DB from embedded seed data; this is the Mokosh equivalent for its single demo set.How
SeedService::load_demo_data -> LoadDemoOutcomeis the explicit-request counterpart toensure_demo_seeded: it reuses the sametenant_has_companiesemptiness gate andseed_rows, but surfaces its outcome (Seededvs.AlreadyHasData) instead of swallowing it. Thedata_transfermodule exposes it as admin-onlyPOST /data/seed-demo, sharing the seed middleware'sSeedServiceArcso an explicit load and the auto-seed agree on the per-process seen set and can never double-seed. The endpoint always returns 200 with{ seeded, message };seeded=falseis the legitimate "already has data" outcome, not an error. The shared multi-user landing tenant (PMS-239) is refused.MOKOSH_DEMO_SEEDdoes not gate this explicit path (it governs the automatic first-visit seed).Behaviour (chosen with Nate)
Additive, only-if-empty: refuse (no wipe, no tenant-name confirm) when the tenant already has data. A single demo dataset, not multiple named templates (deferred as YAGNI).
Tests
tests/seed_demo.rsadds three cases: an empty tenant loads the demo rows and returnsSeeded; a tenant with a pre-existing company writes nothing and returnsAlreadyHasData; the shared landing tenant is refused.cargo check --all-targetsand clippy are clean; the seed suite passes against Postgres.Frontend
The mokosh-apps Settings -> Data "Load demo data" button calls this endpoint (companion PR on branch
feat/PMS-679-load-demo-data-buttonin mokosh-apps).PMS-679