---
phase: 33-currency-system
plan: 02
type: execute
wave: 1
depends_on: [01]
files_modified:
  - drizzle-pg/meta/_journal.json
autonomous: true
requirements: [D-01, D-02, D-03, D-06, D-07]

must_haves:
  truths:
    - "Database schema matches Drizzle schema definitions"
    - "market_prices table exists in the database"
    - "community_prices table exists in the database"
    - "items table has price_currency column"
    - "thread_candidates table has found_price_cents, found_price_currency, found_price_date columns"
  artifacts:
    - path: "drizzle-pg/"
      provides: "Migration SQL file for new tables and columns"
  key_links:
    - from: "src/db/schema.ts"
      to: "drizzle-pg/"
      via: "bun run db:generate"
      pattern: "market_prices|community_prices"
---

<objective>
Generate and apply database migration for the new market pricing tables and columns.

Purpose: [BLOCKING] Schema push — database must match code before any API work can proceed. Without this, TypeScript types pass (from config) but runtime queries fail.
Output: Migration SQL applied to database.
</objective>

<execution_context>
@$HOME/.claude/get-shit-done/workflows/execute-plan.md
@$HOME/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/STATE.md
@.planning/phases/33-currency-system/33-01-SUMMARY.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: [BLOCKING] Generate and push database migration</name>
  <files>drizzle-pg/</files>
  <read_first>src/db/schema.ts, drizzle.config.ts</read_first>
  <action>
Run Drizzle migration generation and push:

1. Generate migration: `bun run db:generate`
   - This reads src/db/schema.ts and produces a SQL migration file in drizzle-pg/
   - Expected: creates new migration for market_prices table, community_prices table, and new columns on items/thread_candidates

2. Apply migration: `bun run db:push`
   - Applies the generated migration to the PostgreSQL database
   - Verify by checking that the migration was applied without errors

3. Verify tables exist by running a quick query or checking the migration output

Note: Drizzle ORM detected, push command is `bun run db:push` (per project CLAUDE.md). Non-TTY compatible — no interactive prompts expected.
  </action>
  <acceptance_criteria>
    - A new migration SQL file exists in drizzle-pg/ containing CREATE TABLE market_prices
    - A new migration SQL file exists in drizzle-pg/ containing CREATE TABLE community_prices
    - Migration SQL contains ALTER TABLE items ADD COLUMN price_currency
    - Migration SQL contains ALTER TABLE thread_candidates ADD COLUMN found_price_cents
    - `bun run db:push` exits with code 0
  </acceptance_criteria>
  <verify>
    <automated>cd /home/jlmak/Projects/jlmak/GearBox && ls drizzle-pg/*.sql | tail -1 | xargs grep -c "market_prices\|community_prices"</automated>
  </verify>
  <done>Database schema matches Drizzle definitions — all new tables and columns exist in the live database</done>
</task>

</tasks>

<threat_model>
## Trust Boundaries

| Boundary | Description |
|----------|-------------|
| None | Schema migration is an internal operation with no external trust boundaries |

## STRIDE Threat Register

| Threat ID | Category | Component | Disposition | Mitigation Plan |
|-----------|----------|-----------|-------------|-----------------|
| T-33-05 | Tampering | migration SQL | accept | Migrations are generated from code and applied by the developer — no external input |
</threat_model>

<verification>
- Migration file exists in drizzle-pg/ with correct DDL
- `bun run db:push` completes successfully
- No runtime errors when querying new tables
</verification>

<success_criteria>
- Database has market_prices and community_prices tables
- items table has price_currency column
- thread_candidates table has found_price_cents, found_price_currency, found_price_date columns
</success_criteria>

<output>
After completion, create `.planning/phases/33-currency-system/33-02-SUMMARY.md`
</output>
