Baseball demo: freshness reseed for Rini University Baseball - #686
Conversation
…ball Screenshots showed the demo team's upcoming game/practice/meeting had drifted into the past (dates were computed relative to whenever seed-rini-baseball-demo.ts last ran), and several premium surfaces (development plans, documents, messaging) had no seeded content at all. Adds scripts/reseed-rini-demo-freshness.ts, an idempotent companion to the base seed that: re-dates the anchor events/games so "this week" has a future game + practice + meeting; seeds 2 development plans (4 goals each, one partially completed) so the goal-checkbox/progress UI demos for both the player and coach; seeds 4 team documents backed by real storage objects in the same `documents` bucket + path convention the app's own upload action uses; seeds a 4-message coach<->player conversation; and re-dates recent lift sessions/readiness check-ins (both the live helm_lifting_* tables and the legacy baseball_readiness_checkins table) so "Recent" reads as current. Rows the base seed already owns are updated in place via partial-column .update() on the same deterministic ids (no destructive delete-then- insert); new rows are keyed under a dedicated 'baseball-demo-reseed-v1' id namespace so re-runs upsert instead of duplicating. Ran against prod with --confirm; verified via SQL (row counts stable across 3 runs, get_baseball_conversations_with_details RPC, and a storage download round-trip on all 4 documents). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CHFRrZkRsAHWTwvxhySkfe
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (3)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
PR Summary by QodoAdd idempotent freshness reseed script for Rini University Baseball demo
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
93 rules 1. createClient imported from @supabase/supabase-js
|
| * (team + org ids below) are written. | ||
| */ | ||
| import 'dotenv/config'; | ||
| import { createClient, type SupabaseClient } from '@supabase/supabase-js'; |
There was a problem hiding this comment.
1. createclient imported from @supabase/supabase-js 📘 Rule violation ⌂ Architecture
This script directly imports and instantiates a Supabase client via @supabase/supabase-js instead of using the shared server-side Supabase client factory. This can bypass centralized configuration and policy controls intended to standardize server-side DB access.
Agent Prompt
## Issue description
`scripts/reseed-rini-demo-freshness.ts` creates a Supabase client by importing `createClient` from `@supabase/supabase-js`, instead of using the shared server-side Supabase client factory.
## Issue Context
The compliance rule requires server-side code paths to obtain Supabase clients exclusively from the shared factory (per project convention). This script runs server-side and performs DB/storage writes.
## Fix Focus Areas
- scripts/reseed-rini-demo-freshness.ts[67-69]
- scripts/reseed-rini-demo-freshness.ts[183-187]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| await upsert('baseball_documents', [{ | ||
| id: docId, | ||
| team_id: TEAM_ID, | ||
| title: doc.title, | ||
| description: doc.description, | ||
| file_url: signedUrl, | ||
| file_type: 'text/plain', | ||
| file_size: buf.byteLength, | ||
| category: doc.category, | ||
| is_player_visible: true, | ||
| uploaded_by: COACH_USER_ID, | ||
| version_count: 1, | ||
| folder: doc.folder, | ||
| }]); |
There was a problem hiding this comment.
4. Document version_count reset 🐞 Bug ≡ Correctness
The reseed upsert always writes baseball_documents.version_count = 1, which will overwrite any higher version_count created by user uploads and can break/lie to the Documents UI (badges/history expectations) on reruns.
Agent Prompt
### Issue description
The reseed script upserts `baseball_documents` with `version_count: 1` every time. If the demo team has uploaded additional versions via the UI, rerunning this script will reset `version_count` back to 1 even though higher versions still exist in `baseball_document_versions`.
### Issue Context
The client UI uses `version_count` for version badges and for some version-history logic. The script is intended to be safely re-runnable in prod.
### Fix Focus Areas
- scripts/reseed-rini-demo-freshness.ts[455-468]
### Suggested fix
For each document:
- Fetch the existing row (or at least `version_count`, and possibly `file_url/file_type/file_size`) before writing.
- If the document already exists, avoid overwriting `version_count` (and consider not overwriting `file_url/file_type/file_size` either), e.g.:
- Use an `update()` for non-version metadata only (title/description/category/folder/is_player_visible/uploaded_by) OR
- Conditionally include `version_count: 1` only on first creation.
- Alternatively, compute `version_count` from `MAX(version_number)` in `baseball_document_versions` for that document and write that value.
This keeps reruns idempotent without regressing existing document/version state.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| * Idempotency: | ||
| * - (1) and (5) are partial-column UPSERTs (`onConflict: 'id'`) against | ||
| * ids the base seed already created — Postgres `ON CONFLICT DO UPDATE | ||
| * SET <listed columns>` never touches columns this script doesn't | ||
| * list, so unrelated columns (roster, box scores, etc.) are untouched. | ||
| * No destructive delete-then-insert anywhere. |
There was a problem hiding this comment.
5. Idempotency comment is stale 🐞 Bug ⚙ Maintainability
The header comment claims sections (1) and (5) use partial-column upserts, but the implementation uses updateMany() (plain updates), which can mislead future maintainers about behavior and constraints.
Agent Prompt
### Issue description
The script header’s idempotency section says (1) and (5) are partial-column UPSERTs, but the code uses `updateMany()` with `.update().eq('id', ...)`.
### Issue Context
This is a demo/prod reseed script; accurate documentation matters for safe reruns and future maintenance.
### Fix Focus Areas
- scripts/reseed-rini-demo-freshness.ts[40-45]
### Suggested fix
Update the header comment to describe the actual mechanism (`updateMany` / partial-column UPDATE) and why it’s used (avoids insert-time NOT NULL validation issues), matching the detailed explanation already present above `updateMany()`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
CI Feedback 🧐A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
Root cause
The demo team (Rini University Baseball) is seeded by
scripts/seed-rini-baseball-demo.ts, which computes every date relativeto whenever it was last run. Real calendar time keeps moving, so the
"upcoming" game/practice/meeting drifted into the past (screenshots
showed the anchor game dated Jun 28, already gone by), readiness
check-ins read as weeks stale, and a few premium surfaces the base seed
never populated at all (development plans, documents, coach<->player
messaging) had no content to demo.
Fix
New idempotent companion script:
scripts/reseed-rini-demo-freshness.ts.days), game vs Coastal State (+3 days), plus the 2 "next" scheduled
games — so "this week" always has a future game + practice + meeting.
(rinin376's player row) gets an
in_progressplan with one completedgoal + two in-progress + one not-started, so the player-facing "My
Development" goal-checkbox/progress-ring UI has real content. Jake
Thompson gets a
sentplan for coach-side list/detail variety.conditioning manual. Real
baseball_documents+baseball_document_versionsrows backed by tiny placeholder.txtfiles uploaded through the exact same
documentsstorage bucket +baseball-documents/<teamId>/<file>path conventionuploadBaseballDocumentActionuses — not fake metadata pointing atnothing.
back-and-forth, most recent unread) so Messages has content.
helm_lifting_*tables and the legacybaseball_readiness_checkinstable a couple of surfaces still read — so the readiness / "today's
lift" panels read as current instead of drifting stale.
Idempotency / safety
lift sessions/program-assignments/results/assignments) are updated
in place via partial-column
.update().eq('id', id)on the SAMEdeterministic ids the base seed minted — never a fresh insert, never a
delete-then-insert. (Initially tried
.upsert()with a partialpayload; Postgres validates an INSERT's column list against NOT-NULL
constraints even when it will resolve via
ON CONFLICT DO UPDATE, sothat failed on these wide tables — switched to plain
.update().)a dedicated
baseball-demo-reseed-v1id namespace — that namespace isthe stable dedupe key / ownership marker, so re-running just upserts
the same rows again.
2acc63ce…) / org / the two demousers. Golf is never touched.
What was actually written (ran against prod with
--confirm)baseball_events(updated)baseball_games(updated)baseball_developmental_plansbaseball_documentsbaseball_document_versionsdocumentsbucket)baseball_conversationsbaseball_conversation_participantsbaseball_messagesbaseball_readiness_checkins(updated)helm_lifting_readiness_checkins(updated)helm_lifting_program_assignments(updated)helm_lifting_sessions(updated)baseball_lift_results(updated)baseball_lift_assignments(updated)Test plan
npx eslint scripts/reseed-rini-demo-freshness.ts— 0 errors, 0 warningsnpx tsc --noEmit --skipLibCheck ...targeted check on the file — 0 errors (thescripts/dir is excluded from the project tsconfig)npx vitest run src/contracts/baseball/demo-stats-smoke.contract.test.ts— 9/9 passed (unaffected; base seed file untouched)--confirmagainst prod; ran a second and third--confirmpass — row counts identical each time (idempotent, no duplicates)helm_lifting_sessionsscheduled dates land -10d/-7d/today/+3d; readiness check-ins land within the last 3 daysget_baseball_conversations_with_details()RPC (the actual read pathuseConversationscalls) returns the seeded conversation with correct unread count, last message, and participant emailsdocumentsbucket and confirmed readable text content🤖 Generated with Claude Code
https://claude.ai/code/session_01CHFRrZkRsAHWTwvxhySkfe