Skip to content

feat(seed): conditionally seed demo locations when their R2 objects exist - #41

Merged
AlaskanTuna merged 1 commit into
mainfrom
feat/seed-demo-locations
Aug 25, 2026
Merged

feat(seed): conditionally seed demo locations when their R2 objects exist#41
AlaskanTuna merged 1 commit into
mainfrom
feat/seed-demo-locations

Conversation

@AlaskanTuna

Copy link
Copy Markdown
Owner

Closes the prisma/seed.ts half of #10. The frontend half landed in #36.

Why it is conditional rather than a plain upsert

I argued against seeding at all in #36, and that reasoning still holds: a seed can write Location rows but cannot create their R2 objects. A row marked ready whose rgbImageUrl/maskPath/monthlyFluxPath point at objects a bucket does not contain fails later and more confusingly than a clean cache miss — the app thinks it has a cached location and then cannot render it.

So seedDemoLocations() writes a row only when it can prove the assets exist. Per location, in order:

  1. Row already within ±0.0001° → skip (idempotent).
  2. No rescued source row with non-null buildingInsightsJson in this database → skip. "the seed never fabricates Solar API payloads." In a fresh environment all four take this path.
  3. Rescued row missing storage paths → skip, naming the missing fields.
  4. HeadObject probe 404s on any path → skip, listing the missing objects, so the cache misses cleanly.
  5. All probes pass → create at the exact demo coordinates, cloning the payload from the rescued row.

Missing R2 env skips the whole phase with one log line, and the demo phase is wrapped so it can never take the required TariffConfig seed down with it.

Idempotency is find-then-create keyed on the same 0.0001 tolerance resolveLocation uses — Location has no unique constraint on lat/lng, so upsert would not work.

Known wart

The demo coordinates are duplicated from frontend/src/lib/demoLocations.ts. A clean import was not possible: the seed runs as plain Node with type stripping and no path aliases, and reaching into frontend/src would drag React types across the workspace boundary. The constant carries a comment naming the other file and the drift risk.

Worth hoisting into shared/ later — noting that shared builds to JS, so the seed would need a runtime path into that build. Drift here is not cosmetic: these coordinates only work because they match cached rows within 11 m, so a stale copy silently converts a cache hit into a Solar API call.

Verified

tsc --noEmit -p backend/tsconfig.json exit 0 · node --check on both files exit 0 · import smoke test exports seedDemoLocations · Prettier clean on both files.

Not executed against any database — the HeadObject path is untested against real credentials. Also note prisma/ is in no tsconfig, so the backend typecheck does not actually cover these files; a direct strict check was run instead.

Implemented by the qwen3.8-max peer session; verified here.

https://claude.ai/code/session_01URDpaxhXyPLWnUQtvowNyM

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f2a423f5-268b-4c4e-a3ab-680a1db93f98


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AlaskanTuna
AlaskanTuna merged commit 82b77cf into main Aug 25, 2026
3 checks passed
@AlaskanTuna
AlaskanTuna deleted the feat/seed-demo-locations branch August 25, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant