--- phase: 04-pdf-ingest plan: 01 subsystem: database tags: [drizzle, postgres, schema, migrations, seed, form-templates] # Dependency graph requires: - phase: 03-agent-portal-shell provides: documents table and portal data layer this plan extends provides: - form_templates table with id (text PK), name, filename (unique), createdAt, updatedAt - documents table extended with formTemplateId (nullable FK) and filePath (nullable text) - Drizzle migration 0002 applied to local PostgreSQL - seeds/forms/ directory tracked via .gitkeep - npm run seed:forms CLI: reads seeds/forms/*.pdf, upserts into form_templates via onConflictDoUpdate affects: [04-02, 04-03, 04-04] # Tech tracking tech-stack: added: [] patterns: - DOTENV_CONFIG_PATH=.env.local prefix for tsx seed scripts (mirrors Phase 3 pattern) - onConflictDoUpdate on filename for idempotent form template upserts - formTemplates table placed above documents table in schema.ts to satisfy FK forward-reference key-files: created: - teressa-copeland-homes/scripts/seed-forms.ts - teressa-copeland-homes/seeds/forms/.gitkeep - teressa-copeland-homes/drizzle/0002_wealthy_zzzax.sql - teressa-copeland-homes/drizzle/meta/0002_snapshot.json modified: - teressa-copeland-homes/src/lib/db/schema.ts - teressa-copeland-homes/package.json - teressa-copeland-homes/drizzle/meta/_journal.json key-decisions: - "formTemplates table uses text PK (crypto.randomUUID()) — consistent with all other tables in schema.ts" - "seed:forms uses DOTENV_CONFIG_PATH=.env.local prefix — dotenv/config reads .env by default but project uses .env.local" - "formTemplateId and filePath are nullable — custom uploads have no template, legacy rows have no file path" - "onConflictDoUpdate on filename column — enables idempotent monthly re-run when PDFs change names" patterns-established: - "Seed scripts: DOTENV_CONFIG_PATH=.env.local npx tsx scripts/