Skip to content

Data Seed

The seed mechanism populates the database (D1 on the backend and IndexedDB on the frontend) with demo data as soon as the application is accessed for the first time in development and staging environments. In production, the seed is completely disabled — all data is real, registered by the users themselves.

The seed creates 5 users with distinct roles and shared password senha123: admin@neemias.local (ADMIN), chamador@neemias.local (CHAMADOR), relatorios@neemias.local (RELATORIOS), cadastro@neemias.local (CADASTRO), and a multi-role user with CHAMADOR + RESPONSAVEL. Each has the permission set defined by the RBAC system (packages/permissions).

In addition to users, the seed inserts 500 students with realistic Brazilian names (~100 first names × ~50 surnames), DiceBear avatars (micah style, conservative, deterministic), guardian data, phones, complete addresses, allergies, special needs, and full sociodemographic fields (family structure, economic vulnerability, domestic violence, school status, etc.). 7 classes are created (Nursery, Toddler, Kindergarten, Children, Juniors 1, Juniors 2, Pre-Teens) with bell-curve distribution (heavier in middle age groups), and 20 nuclei (14 in Sky Blue region with children, 1 in each of the other 6 regions). The seed generates persona-driven attendance events (consistent 60%, sporadic 25%, at-risk 10%, chronic 5%) with a seasonal dip (15% drop in week 4 of each cycle), distributed across 4 class slots (Tuesday 8pm, Friday 7:30pm, Sunday 9am, Sunday 7pm) with sessions pre-computed for the last 8 weeks (56 days).

Data generation is handled by the shared @neemias/seed-data package (packages/seed-data/), ensuring frontend (SQLite WASM) and backend (D1) produce identical data from the same pure functions.

Environment control is handled by the DEPLOY_ENV variable (or VITE_DEPLOY_ENV on the frontend). The frontend (app/src/modules/_dev/seed.ts) checks if __DEPLOY_ENV__ === "prod" and aborts the seed in that case; otherwise, it populates local IndexedDB via Dexie. The backend exposes the POST /api/v1/_seed endpoint (available only in development), which inserts the same data directly into Cloudflare D1. This endpoint has an idempotency guard: if the users table already contains records, it returns HTTP 409 (ALREADY_SEEDED), preventing accidental duplication.

Triggering is automatic on first access (frontend) or on demand via HTTP call (backend). To manually trigger the backend seed, simply send a POST to /api/v1/_seed with the Worker running locally (wrangler dev). The default password can be changed via the SEED_PASSWORD environment variable in wrangler.toml or .dev.vars.

⚠️ Section under expansion.


Source: workers/src/routes/seed.ts and app/src/modules/_dev/seed.ts

Distributed under MIT License.