docs(18-01): complete template schema plan — documentTemplates table + migration 0012

- SUMMARY.md created for phase 18 plan 01
- STATE.md: plan advanced to 18-02, progress 97%, decisions recorded
- ROADMAP.md: phase 18 progress updated (1/2 plans complete)
- REQUIREMENTS.md: TMPL-01 marked complete
This commit is contained in:
Chandler Copeland
2026-04-06 12:16:09 -06:00
parent c33c4ec075
commit 752a6b7509
4 changed files with 98 additions and 17 deletions

View File

@@ -128,7 +128,7 @@
### Template Management ### Template Management
- [ ] **TMPL-01**: Agent can create a new template by selecting a PDF from the forms library - [x] **TMPL-01**: Agent can create a new template by selecting a PDF from the forms library
- [ ] **TMPL-02**: Agent can rename a template - [ ] **TMPL-02**: Agent can rename a template
- [ ] **TMPL-03**: Agent can delete a template (soft-delete — preserved if any documents were created from it) - [ ] **TMPL-03**: Agent can delete a template (soft-delete — preserved if any documents were created from it)
- [ ] **TMPL-04**: Agent can view a list of all saved templates with the form name and field count - [ ] **TMPL-04**: Agent can view a list of all saved templates with the form name and field count
@@ -270,7 +270,7 @@ Which phases cover which requirements. Updated during roadmap creation.
| DEPLOY-03 | Phase 17 | Complete | | DEPLOY-03 | Phase 17 | Complete |
| DEPLOY-04 | Phase 17 | Complete | | DEPLOY-04 | Phase 17 | Complete |
| DEPLOY-05 | Phase 17 | Complete | | DEPLOY-05 | Phase 17 | Complete |
| TMPL-01 | Phase 18 | Pending | | TMPL-01 | Phase 18 | Complete |
| TMPL-02 | Phase 18 | Pending | | TMPL-02 | Phase 18 | Pending |
| TMPL-03 | Phase 18 | Pending | | TMPL-03 | Phase 18 | Pending |
| TMPL-04 | Phase 18 | Pending | | TMPL-04 | Phase 18 | Pending |

View File

@@ -399,7 +399,7 @@ Plans:
**Plans**: 2 plans **Plans**: 2 plans
Plans: Plans:
- [ ] 18-01-PLAN.md — Drizzle schema: documentTemplates table definition + 0012 migration - [x] 18-01-PLAN.md — Drizzle schema: documentTemplates table definition + 0012 migration
- [ ] 18-02-PLAN.md — CRUD API routes: GET/POST /api/templates, PATCH/DELETE /api/templates/[id] - [ ] 18-02-PLAN.md — CRUD API routes: GET/POST /api/templates, PATCH/DELETE /api/templates/[id]
**UI hint**: no **UI hint**: no
@@ -455,6 +455,6 @@ Phases execute in numeric order: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 →
| 15. Multi-Signer Backend | v1.2 | 3/3 | Complete | 2026-04-03 | | 15. Multi-Signer Backend | v1.2 | 3/3 | Complete | 2026-04-03 |
| 16. Multi-Signer UI | v1.2 | 1/4 | Complete | 2026-04-03 | | 16. Multi-Signer UI | v1.2 | 1/4 | Complete | 2026-04-03 |
| 17. Docker Deployment | v1.2 | 2/2 | Complete | 2026-04-03 | | 17. Docker Deployment | v1.2 | 2/2 | Complete | 2026-04-03 |
| 18. Template Schema and CRUD API | v1.3 | 0/TBD | Not started | - | | 18. Template Schema and CRUD API | v1.3 | 1/2 | In Progress| |
| 19. Template Editor UI | v1.3 | 0/TBD | Not started | - | | 19. Template Editor UI | v1.3 | 0/TBD | Not started | - |
| 20. Apply Template and Portal Nav | v1.3 | 0/TBD | Not started | - | | 20. Apply Template and Portal Nav | v1.3 | 0/TBD | Not started | - |

View File

@@ -1,16 +1,16 @@
--- ---
gsd_state_version: 1.0 gsd_state_version: 1.0
milestone: v1.3 milestone: v1.1
milestone_name: Document Templates milestone_name: Smart Document Preparation
status: roadmap defined status: executing
stopped_at: v1.3 roadmap created — Phases 18-20 defined, ready for plan-phase 18 stopped_at: Completed 18-01-PLAN.md — documentTemplates schema and migration 0012
last_updated: "2026-04-06T00:00:00.000Z" last_updated: "2026-04-06T18:15:59.504Z"
last_activity: 2026-04-06 last_activity: 2026-04-06
progress: progress:
total_phases: 22 total_phases: 20
completed_phases: 18 completed_phases: 18
total_plans: 58 total_plans: 60
completed_plans: 57 completed_plans: 58
percent: 82 percent: 82
--- ---
@@ -24,9 +24,9 @@ See: .planning/PROJECT.md (updated 2026-04-03)
## Current Position ## Current Position
Phase: 18 (template-schema-and-crud-api) — NOT STARTED Phase: 18 (template-schema-and-crud-api) — EXECUTING
Plan: 0 of TBD Plan: 2 of 2
Status: Roadmap defined — awaiting plan-phase 18 Status: Ready to execute
Last activity: 2026-04-06 Last activity: 2026-04-06
## Note on v1.1 ## Note on v1.1
@@ -103,6 +103,7 @@ Progress: [████████████░░░] 82% (18/22 phases comp
| Phase 16-multi-signer-ui P01 | 5 | 2 tasks | 6 files | | Phase 16-multi-signer-ui P01 | 5 | 2 tasks | 6 files |
| Phase 17-docker-deployment P01 | 2 | 2 tasks | 4 files | | Phase 17-docker-deployment P01 | 2 | 2 tasks | 4 files |
| Phase 17 P02 | 3 | 3 tasks | 6 files | | Phase 17 P02 | 3 | 3 tasks | 6 files |
| Phase 18-template-schema-and-crud-api P01 | 4 | 2 tasks | 2 files |
## Accumulated Context ## Accumulated Context
@@ -188,6 +189,9 @@ Recent decisions affecting v1.1 work:
- [Phase 17]: node:20-slim (Debian) not Alpine — @napi-rs/canvas requires glibc, Alpine musl incompatible - [Phase 17]: node:20-slim (Debian) not Alpine — @napi-rs/canvas requires glibc, Alpine musl incompatible
- [Phase 17]: seeds/ copied into runner stage at /app/seeds — runtime dependency for form library import feature - [Phase 17]: seeds/ copied into runner stage at /app/seeds — runtime dependency for form library import feature
- [Phase 17]: platform=linux/amd64 on all 3 Dockerfile FROM lines — home server is x86_64 - [Phase 17]: platform=linux/amd64 on all 3 Dockerfile FROM lines — home server is x86_64
- [Phase 18-template-schema-and-crud-api]: signatureFields nullable JSONB: template starts empty; Phase 19 fills it via PATCH
- [Phase 18-template-schema-and-crud-api]: formTemplateId FK has no onDelete cascade: archived templates remain even if form is removed
- [Phase 18-template-schema-and-crud-api]: archivedAt nullable timestamp: NULL = active, soft-delete only
### v1.2 Pre-decisions (from research) ### v1.2 Pre-decisions (from research)
@@ -223,6 +227,6 @@ None yet.
## Session Continuity ## Session Continuity
Last session: 2026-04-06T00:00:00.000Z Last session: 2026-04-06T18:15:59.498Z
Stopped at: v1.3 roadmap created — Phases 18-20 defined; ROADMAP.md, STATE.md, REQUIREMENTS.md updated Stopped at: Completed 18-01-PLAN.md — documentTemplates schema and migration 0012
Resume file: None Resume file: None

View File

@@ -0,0 +1,77 @@
---
phase: 18-template-schema-and-crud-api
plan: "01"
subsystem: database-schema
tags: [drizzle, schema, migration, postgresql]
dependency_graph:
requires: [formTemplates table (form_templates), SignatureFieldData interface]
provides: [documentTemplates table (document_templates), documentTemplatesRelations]
affects: [Phase 19 template editor, Phase 20 apply-template endpoint]
tech_stack:
added: []
patterns: [drizzle pgTable, jsonb $type, nullable timestamp soft-delete, FK no-cascade]
key_files:
created:
- teressa-copeland-homes/drizzle/0012_ancient_blue_shield.sql
modified:
- teressa-copeland-homes/src/lib/db/schema.ts
decisions:
- "signatureFields nullable JSONB: template starts empty; Phase 19 fills it via PATCH"
- "formTemplateId FK has no onDelete cascade: archived templates remain even if form is removed"
- "archivedAt nullable timestamp: NULL = active; soft-delete only (no hard deletes)"
- "updatedAt set explicitly in UPDATE queries, not via DB trigger (existing pattern)"
metrics:
duration: "4 min"
completed_date: "2026-04-06"
tasks_completed: 2
files_changed: 2
---
# Phase 18 Plan 01: Template Schema and Migration Summary
**One-liner:** Drizzle `document_templates` table with 7 columns, nullable JSONB fields, soft-delete via `archivedAt`, FK to `form_templates` with no cascade, and auto-generated SQL migration 0012.
## Tasks Completed
| Task | Name | Commit | Files |
|------|------|--------|-------|
| 1 | Add documentTemplates table to schema.ts | 9e677f9 | teressa-copeland-homes/src/lib/db/schema.ts |
| 2 | Generate Drizzle migration | c33c4ec | teressa-copeland-homes/drizzle/0012_ancient_blue_shield.sql |
## What Was Built
Added the `documentTemplates` Drizzle table definition to `schema.ts` immediately after `formTemplates`. The table has exactly 7 columns per D-02:
- `id` — TEXT PRIMARY KEY via `crypto.randomUUID()`
- `name` — TEXT NOT NULL
- `formTemplateId` — TEXT NOT NULL, FK to `formTemplates.id` with no `onDelete` (D-06)
- `signatureFields` — JSONB nullable, typed as `SignatureFieldData[]` (D-04)
- `archivedAt` — TIMESTAMP nullable, soft-delete sentinel (D-07)
- `createdAt` — TIMESTAMP NOT NULL DEFAULT NOW()
- `updatedAt` — TIMESTAMP NOT NULL DEFAULT NOW()
Also added `documentTemplatesRelations` joining to `formTemplates` via `formTemplateId`.
Generated migration `0012_ancient_blue_shield.sql` via `drizzle-kit generate`. The migration contains only a `CREATE TABLE` statement and an `ALTER TABLE ... ADD CONSTRAINT` for the FK — no alterations to existing tables.
## Verification
- `npx tsc --noEmit` — zero errors
- `ls drizzle/0012_*.sql` — exactly one migration file (0012_ancient_blue_shield.sql)
- `grep "document_templates" drizzle/0012_ancient_blue_shield.sql` — CREATE TABLE present
- `grep "form_template_id" drizzle/0012_ancient_blue_shield.sql` — FK column present
## Deviations from Plan
None — plan executed exactly as written.
## Known Stubs
None — this plan is schema-only. No UI or API routes were implemented. Phase 18-02 handles the CRUD API routes.
## Self-Check: PASSED
- `teressa-copeland-homes/src/lib/db/schema.ts` — FOUND, contains documentTemplates export
- `teressa-copeland-homes/drizzle/0012_ancient_blue_shield.sql` — FOUND, contains CREATE TABLE document_templates
- Commit 9e677f9 — FOUND
- Commit c33c4ec — FOUND