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)"