---
phase: quick
plan: 260406-j44
subsystem: database
tags: [seed-data, dev-tooling, bikepacking]
dependency_graph:
  requires: [src/db/schema.ts, src/db/seed-global-items.ts, src/db/index.ts]
  provides: [src/db/dev-seed.ts, src/db/dev-seed-data.ts, db:seed:dev script]
  affects: [local development workflow]
tech_stack:
  added: []
  patterns: [idempotent seed script, FK-ordered insertion, data/logic separation]
key_files:
  created: [src/db/dev-seed-data.ts, src/db/dev-seed.ts]
  modified: [package.json]
decisions:
  - Separated data constants (dev-seed-data.ts) from runner logic (dev-seed.ts) for maintainability
  - Used logtoSub="dev-user-seed" as idempotency sentinel — single check gates entire script
  - Global items are deduplicated by brand+model to avoid conflicts with existing seed-global-items.json data
  - Tag assignments skip existing links to stay idempotent at the row level
metrics:
  duration: ~4m
  completed: 2026-04-06
  tasks_completed: 2
  tasks_total: 2
  files_created: 2
  files_modified: 1
---

# Quick Task 260406-j44: Comprehensive Dev Seed Script Summary

Idempotent dev seed script populating PostgreSQL with 36 global items, 30 tag assignments, 10 categories, 17 user items (10 catalog-linked + 7 standalone), 3 threads with 7 candidates, 2 setups, and user settings for realistic bikepacking gear development.

## Commits

| # | Hash | Message |
|---|------|---------|
| 1 | 24f3a8a | feat(quick-260406-j44): add dev seed data constants for bikepacking gear |
| 2 | eb7f37f | feat(quick-260406-j44): add idempotent dev seed runner and db:seed:dev script |

## Task Details

### Task 1: Create seed data constants
Created `src/db/dev-seed-data.ts` with typed constant arrays covering all entity types. Data uses real bikepacking gear brands (Revelate Designs, Zpacks, Enlightened Equipment, Nitecore, etc.) with accurate weights and prices in cents. Includes a `categoryDisplayName()` helper for mapping seed category slugs to display names.

### Task 2: Create seed runner and wire npm script
Created `src/db/dev-seed.ts` with FK-ordered insertion (users -> categories -> global items -> tags -> items -> threads -> candidates -> setups -> setup_items -> settings). Idempotency check queries for `logtoSub = "dev-user-seed"`. Global items are deduplicated against existing `seed-global-items.json` data by brand+model. Added `db:seed:dev` script to package.json.

## Deviations from Plan

### Auto-fixed Issues

**1. [Rule 1 - Bug] Added undefined guards on .returning() results**
- **Found during:** Task 2 type-check
- **Issue:** TypeScript strict mode flagged `.returning()` destructured results as possibly undefined
- **Fix:** Added `if (!result) throw new Error(...)` guards after each `.returning()` call
- **Files modified:** src/db/dev-seed.ts
- **Commit:** eb7f37f

## Known Stubs

None — all data is fully wired with valid FK references.

## Self-Check: PASSED
