From 9e677f95052092b4ea76c6d1092a879d3b3e8fbe Mon Sep 17 00:00:00 2001 From: Chandler Copeland Date: Mon, 6 Apr 2026 12:15:01 -0600 Subject: [PATCH] feat(18-01): add documentTemplates table and relation to schema.ts - Add document_templates pgTable with 7 columns: id, name, formTemplateId, signatureFields, archivedAt, createdAt, updatedAt - formTemplateId FK references formTemplates.id with no onDelete cascade - signatureFields typed as SignatureFieldData[] via jsonb, nullable (template starts empty) - archivedAt nullable timestamp for soft-delete (NULL = active) - Add documentTemplatesRelations joining to formTemplates --- teressa-copeland-homes/src/lib/db/schema.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/teressa-copeland-homes/src/lib/db/schema.ts b/teressa-copeland-homes/src/lib/db/schema.ts index 71e634d..3942590 100644 --- a/teressa-copeland-homes/src/lib/db/schema.ts +++ b/teressa-copeland-homes/src/lib/db/schema.ts @@ -98,6 +98,20 @@ export const formTemplates = pgTable("form_templates", { updatedAt: timestamp("updated_at").defaultNow().notNull(), }); +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(), + archivedAt: timestamp("archived_at"), + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), +}); + +export const documentTemplatesRelations = relations(documentTemplates, ({ one }) => ({ + formTemplate: one(formTemplates, { fields: [documentTemplates.formTemplateId], references: [formTemplates.id] }), +})); + /** Shape of each entry in documents.signers JSONB array. */ export interface DocumentSigner { email: string;