Skip to content

Add database seed script and prod seeding job - #116

Merged
mirek1112 merged 1 commit into
mainfrom
feat/db-seed-script
Jun 25, 2026
Merged

mirek1112 merged 1 commit into
mainfrom
feat/db-seed-script

Conversation

@mirek1112

@mirek1112 mirek1112 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Seeds catalog/lookup data (cities, locations, categories, tags, items, copies). Idempotent: skips when cities already exist unless forced. Adds npm scripts (seed, seed:prod) and scripts/seed-prod.sh to run the seed as a one-off Cloud Run Job against the deployed backend.

Summary by CodeRabbit

  • New Features
    • Added database seeding support for local development and production environments.
    • Introduced a production-friendly seed workflow that can run as a one-off cloud job.
    • Seeding now populates core catalog data, locations, item copies, and related metadata in a consistent way.
  • Bug Fixes
    • Added safeguards to avoid overwriting existing seeded data unless a force option is used.

Seeds catalog/lookup data (cities, locations, categories, tags, items,
copies). Idempotent: skips when cities already exist unless forced.
Adds npm scripts (seed, seed:prod) and scripts/seed-prod.sh to run the
seed as a one-off Cloud Run Job against the deployed backend.
@mirek1112
mirek1112 merged commit 5cd7b67 into main Jun 25, 2026
2 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e513628d-ade9-4f4b-a91d-7e1535aa724d

📥 Commits

Reviewing files that changed from the base of the PR and between 2ebf246 and 6458ad2.

📒 Files selected for processing (3)
  • backend/package.json
  • backend/scripts/seed-prod.sh
  • backend/src/db/seed.ts

📝 Walkthrough

Walkthrough

Adds seed npm scripts, a deterministic database seeding routine for cities, locations, categories, tags, items, and item copies, and a Bash wrapper that creates, updates, and runs a Cloud Run Job for production seeding.

Changes

Seed tooling and production job flow

Layer / File(s) Summary
Seed routines
backend/src/db/seed.ts
Deterministic Faker setup, reusable upsert logic, and the exported seeding routine insert cities, locations, categories, tags, items, and item copies with conditional skip behavior and count logging.
Seed CLI wiring
backend/package.json, backend/src/db/seed.ts
Adds seed and seed:prod npm scripts and an executable entrypoint that initializes the shared data source, calls the seed routine, and destroys the connection in a finally block.
Production job launcher
backend/scripts/seed-prod.sh
Reads deployment defaults, resolves the deployed backend service, extracts env vars and secrets, creates or updates the Cloud Run Job, and runs it with wait enabled.

Sequence Diagram(s)

sequenceDiagram
  participant seedProd as "seed-prod.sh"
  participant gcloud as "gcloud"
  participant cloudService as "backend Cloud Run service"
  participant cloudJob as "Cloud Run Job"
  seedProd->>gcloud: describe backend service
  gcloud->>cloudService: read image, Cloud SQL annotation, env vars, secrets
  cloudService-->>gcloud: service definition
  seedProd->>gcloud: create or update job with backend/dist/db/seed.js
  gcloud->>cloudJob: apply job spec
  seedProd->>gcloud: run job --wait
  gcloud->>cloudJob: execute seed entrypoint
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hopped through seeds in moonlit rows,
and watched the Cloud Run garden grow.
With tags and items, neat and spry,
the job ran once beneath the sky.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/db-seed-script

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.

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