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
This commit is contained in:
Chandler Copeland
2026-04-06 12:15:01 -06:00
parent 421688f7f7
commit 9e677f9505

View File

@@ -98,6 +98,20 @@ export const formTemplates = pgTable("form_templates", {
updatedAt: timestamp("updated_at").defaultNow().notNull(), 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<SignatureFieldData[]>(),
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. */ /** Shape of each entry in documents.signers JSONB array. */
export interface DocumentSigner { export interface DocumentSigner {
email: string; email: string;