From bbbbdbed5e7339490894e44b609ae12806bfd812 Mon Sep 17 00:00:00 2001 From: Chandler Copeland Date: Thu, 19 Mar 2026 21:32:30 -0600 Subject: [PATCH] feat(04-01): add formTemplates table and extend documents schema - Add formTemplates table (id text PK, name, filename unique, createdAt, updatedAt) - Add formTemplateId (nullable FK) and filePath (nullable text) to documents table - Generate and apply migration 0002_wealthy_zzzax.sql - Create seeds/forms/.gitkeep to track seed directory in git --- .../drizzle/0002_wealthy_zzzax.sql | 12 + .../drizzle/meta/0002_snapshot.json | 265 ++++++++++++++++++ .../drizzle/meta/_journal.json | 7 + teressa-copeland-homes/seeds/forms/.gitkeep | 0 teressa-copeland-homes/src/lib/db/schema.ts | 10 + 5 files changed, 294 insertions(+) create mode 100644 teressa-copeland-homes/drizzle/0002_wealthy_zzzax.sql create mode 100644 teressa-copeland-homes/drizzle/meta/0002_snapshot.json create mode 100644 teressa-copeland-homes/seeds/forms/.gitkeep diff --git a/teressa-copeland-homes/drizzle/0002_wealthy_zzzax.sql b/teressa-copeland-homes/drizzle/0002_wealthy_zzzax.sql new file mode 100644 index 0000000..2fb7189 --- /dev/null +++ b/teressa-copeland-homes/drizzle/0002_wealthy_zzzax.sql @@ -0,0 +1,12 @@ +CREATE TABLE "form_templates" ( + "id" text PRIMARY KEY NOT NULL, + "name" text NOT NULL, + "filename" text NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "form_templates_filename_unique" UNIQUE("filename") +); +--> statement-breakpoint +ALTER TABLE "documents" ADD COLUMN "form_template_id" text;--> statement-breakpoint +ALTER TABLE "documents" ADD COLUMN "file_path" text;--> statement-breakpoint +ALTER TABLE "documents" ADD CONSTRAINT "documents_form_template_id_form_templates_id_fk" FOREIGN KEY ("form_template_id") REFERENCES "public"."form_templates"("id") ON DELETE no action ON UPDATE no action; \ No newline at end of file diff --git a/teressa-copeland-homes/drizzle/meta/0002_snapshot.json b/teressa-copeland-homes/drizzle/meta/0002_snapshot.json new file mode 100644 index 0000000..d53c6d2 --- /dev/null +++ b/teressa-copeland-homes/drizzle/meta/0002_snapshot.json @@ -0,0 +1,265 @@ +{ + "id": "2b5e908a-37da-4cb2-b42e-066a7c727965", + "prevId": "88e82a5b-fc38-4c78-b24f-2bcc020f874c", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.clients": { + "name": "clients", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.documents": { + "name": "documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "document_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'Draft'" + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "form_template_id": { + "name": "form_template_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "documents_client_id_clients_id_fk": { + "name": "documents_client_id_clients_id_fk", + "tableFrom": "documents", + "tableTo": "clients", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "documents_form_template_id_form_templates_id_fk": { + "name": "documents_form_template_id_form_templates_id_fk", + "tableFrom": "documents", + "tableTo": "form_templates", + "columnsFrom": [ + "form_template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.form_templates": { + "name": "form_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "form_templates_filename_unique": { + "name": "form_templates_filename_unique", + "nullsNotDistinct": false, + "columns": [ + "filename" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.document_status": { + "name": "document_status", + "schema": "public", + "values": [ + "Draft", + "Sent", + "Viewed", + "Signed" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/teressa-copeland-homes/drizzle/meta/_journal.json b/teressa-copeland-homes/drizzle/meta/_journal.json index 96ad59f..945573f 100644 --- a/teressa-copeland-homes/drizzle/meta/_journal.json +++ b/teressa-copeland-homes/drizzle/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1773958608977, "tag": "0001_watery_blindfold", "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1773977523128, + "tag": "0002_wealthy_zzzax", + "breakpoints": true } ] } \ No newline at end of file diff --git a/teressa-copeland-homes/seeds/forms/.gitkeep b/teressa-copeland-homes/seeds/forms/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/teressa-copeland-homes/src/lib/db/schema.ts b/teressa-copeland-homes/src/lib/db/schema.ts index e3398c2..95ef1c0 100644 --- a/teressa-copeland-homes/src/lib/db/schema.ts +++ b/teressa-copeland-homes/src/lib/db/schema.ts @@ -22,6 +22,14 @@ export const clients = pgTable("clients", { updatedAt: timestamp("updated_at").defaultNow().notNull(), }); +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(), +}); + export const documents = pgTable("documents", { id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()), name: text("name").notNull(), @@ -31,4 +39,6 @@ export const documents = pgTable("documents", { status: documentStatusEnum("status").notNull().default("Draft"), sentAt: timestamp("sent_at"), createdAt: timestamp("created_at").defaultNow().notNull(), + formTemplateId: text("form_template_id").references(() => formTemplates.id), + filePath: text("file_path"), });