6.9 KiB
phase, plan, type, wave, depends_on, files_modified, autonomous, requirements, must_haves
| phase | plan | type | wave | depends_on | files_modified | autonomous | requirements | must_haves | |||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 18-template-schema-and-crud-api | 01 | execute | 1 |
|
true |
|
|
Purpose: Every subsequent template feature (editor, API, apply-to-document) depends on this table existing. This plan establishes the schema foundation.
Output: Updated schema.ts with documentTemplates table + drizzle/0012_*.sql migration file.
<execution_context> @$HOME/.claude/get-shit-done/workflows/execute-plan.md @$HOME/.claude/get-shit-done/templates/summary.md </execution_context>
@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/18-template-schema-and-crud-api/18-CONTEXT.mdFrom teressa-copeland-homes/src/lib/db/schema.ts:
export interface SignatureFieldData {
id: string;
page: number;
x: number;
y: number;
width: number;
height: number;
type?: SignatureFieldType;
signerEmail?: string;
hint?: string;
}
export const formTemplates = pgTable("form_templates", {
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
name: text("name").notNull(),
filename: text("filename").notNull().unique(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
Existing migration files: 0000 through 0011. Next migration is 0012.
Task 1: Add documentTemplates table to schema.ts - teressa-copeland-homes/src/lib/db/schema.ts teressa-copeland-homes/src/lib/db/schema.ts Add the `documentTemplates` table definition to schema.ts, placed immediately after the `formTemplates` table definition (before the `documents` table). Per D-01, D-02, D-03, D-04, D-05, D-06:export const documentTemplates = pgTable("document_templates", {
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
name: text("name").notNull(),
formTemplateId: text("form_template_id").notNull().references(() => formTemplates.id),
signatureFields: jsonb("signature_fields").$type<SignatureFieldData[]>(),
archivedAt: timestamp("archived_at"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
Key points:
signatureFieldsis nullable (per D-04) — template starts empty, editor fills it in Phase 19formTemplateIdFK has NOonDeleteoption (per D-06) — no cascadearchivedAtis nullable — NULL means active (per D-07)updatedAtmust be set explicitly in PATCH queries, not via DB trigger (per D-05)
Also add a relation from documentTemplates to formTemplates:
export const documentTemplatesRelations = relations(documentTemplates, ({ one }) => ({
formTemplate: one(formTemplates, { fields: [documentTemplates.formTemplateId], references: [formTemplates.id] }),
}));
Do NOT add onDelete: 'cascade' to the formTemplateId FK. Per D-06, if a form is removed, templates referencing it should remain.
cd /Users/ccopeland/temp/red/teressa-copeland-homes && npx tsc --noEmit 2>&1 | head -20
<acceptance_criteria>
- documentTemplates export exists in schema.ts
- Table has exactly 7 columns: id, name, formTemplateId, signatureFields, archivedAt, createdAt, updatedAt
- formTemplateId references formTemplates.id with no onDelete
- signatureFields typed as SignatureFieldData[] via $type
- archivedAt is nullable timestamp (no .notNull())
- npx tsc --noEmit passes with zero errors
</acceptance_criteria>
documentTemplates table and relations defined in schema.ts, TypeScript compiles cleanly
cd teressa-copeland-homes && npx drizzle-kit generate
This will produce drizzle/0012_*.sql (Drizzle auto-names it). The migration should contain a CREATE TABLE "document_templates" statement with all 7 columns and the FK constraint to form_templates.
After generation, read the migration file to verify it contains the expected CREATE TABLE statement and FK constraint. The migration should NOT contain any DROP or ALTER statements on existing tables.
Commit both schema.ts and the migration file.
ls /Users/ccopeland/temp/red/teressa-copeland-homes/drizzle/0012_.sql && grep -l "document_templates" /Users/ccopeland/temp/red/teressa-copeland-homes/drizzle/0012_.sql
<acceptance_criteria>
- Migration file drizzle/0012_*.sql exists
- File contains CREATE TABLE for document_templates
- File contains FK constraint referencing form_templates(id)
- File does NOT alter or drop any existing tables
- No other 0012 migration files exist (exactly one)
</acceptance_criteria>
Migration 0012 generated with CREATE TABLE document_templates, FK to form_templates, all 7 columns
<success_criteria>
- documentTemplates table defined in schema.ts with all 7 columns per D-02
- Drizzle relation to formTemplates exists
- Migration 0012_*.sql generated and contains CREATE TABLE
- TypeScript compiles with zero errors </success_criteria>