From 5f30a9c4955b82c382047bf82b4c2ba7c5d054a1 Mon Sep 17 00:00:00 2001 From: Elshad Toklayev Date: Sun, 31 May 2026 20:59:47 +0300 Subject: [PATCH] fix(seed): make the demo dataset usable out of the box The README's db:seed produced data that left key screens empty on a fresh local database: - Trending returned zero rows: seeded plays were anchored to a fixed past date (2026-05-23), so the "last 7 days" window was empty on any later date. Anchor seeded play timestamps to the run date instead (run.ts); catalog generation stays deterministic since the PRNG seed is unchanged. - Only 3 of 5 seeded users had history, so logging in as sam/riley showed empty analytics. Seed history for all five users and make each fuller (historyUsers 3 -> 5, historyPerUser 60-110 -> 90-160). - setup.sh migrated but never seeded, so `pnpm setup && pnpm dev` left an empty UI. Run db:seed during setup (skip with SKIP_SEED=1) and print the demo login. - README: add the seed step to the local-dev happy path and document the demo account (alex@statify.local / statify123). --- README.md | 17 +++++++++++++++++ packages/db/src/seed/generate.ts | 4 ++-- packages/db/src/seed/run.ts | 4 +++- scripts/setup.sh | 10 ++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 927c09f..0a0e2c5 100644 --- a/README.md +++ b/README.md @@ -131,12 +131,29 @@ Apply database migrations: pnpm --filter @statify/db prisma:migrate:dev ``` +Seed a small demo dataset (catalog, accounts, and listening history) so the +app has data on first run: + +```bash +pnpm --filter @statify/db db:seed +``` + Run the frontend and backend: ```bash pnpm dev ``` +Then sign in with a seeded account to see populated analytics: + +| Field | Value | +| -------- | -------------------- | +| Email | `alex@statify.local` | +| Password | `statify123` | + +All five seeded accounts (`admin`, `alex`, `jordan`, `sam`, `riley`) share the +same password and have listening history. + Default local URLs: | Service | URL | diff --git a/packages/db/src/seed/generate.ts b/packages/db/src/seed/generate.ts index 03ac149..a199d9e 100644 --- a/packages/db/src/seed/generate.ts +++ b/packages/db/src/seed/generate.ts @@ -71,8 +71,8 @@ export const DEFAULT_SEED_COUNTS: SeedCounts = { albums: 200, tracks: 600, playlists: 60, - historyUsers: 3, - historyPerUser: { min: 60, max: 110 }, + historyUsers: 5, + historyPerUser: { min: 90, max: 160 }, historyDays: 21, }; diff --git a/packages/db/src/seed/run.ts b/packages/db/src/seed/run.ts index e7614aa..46d72cd 100644 --- a/packages/db/src/seed/run.ts +++ b/packages/db/src/seed/run.ts @@ -79,7 +79,9 @@ export async function runSeed( }); const userIdByEmail = new Map(users.map((u) => [u.email, u.id])); - const corpus = generateCorpus(counts); + // Anchor seeded play timestamps to the run date so time-windowed analytics + // (e.g. Trending: last 7 days vs the prior 7) have data on the current date. + const corpus = generateCorpus(counts, new Date()); const artistIds = await insertArtists(prisma, corpus.artists); logger.info(`Inserted ${corpus.artists.length} artists`); diff --git a/scripts/setup.sh b/scripts/setup.sh index 8f99d94..b290bc7 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -33,11 +33,17 @@ pnpm install pnpm --filter @statify/db run prisma:generate pnpm --filter @statify/db run prisma:migrate:deploy +# Seed a small demo dataset so the app has data on first run. +# Set SKIP_SEED=1 to skip this (e.g. for a production bootstrap). +if [[ "${SKIP_SEED:-0}" != "1" ]]; then + pnpm --filter @statify/db run db:seed +fi + # Build steps decide NODE_ENV themselves; don't leak a dev value from .env. unset NODE_ENV pnpm build echo echo "setup complete." -echo " next: pnpm dev # start api on :4000 and web on :3000" -echo " seed: pnpm --filter @statify/db run db:seed" +echo " next: pnpm dev # start api on :4000 and web on :3000" +echo " login: alex@statify.local / statify123 (a seeded account with data)"