diff --git a/teressa-copeland-homes/drizzle/0001_watery_blindfold.sql b/teressa-copeland-homes/drizzle/0001_watery_blindfold.sql new file mode 100644 index 0000000..3d86b3c --- /dev/null +++ b/teressa-copeland-homes/drizzle/0001_watery_blindfold.sql @@ -0,0 +1,19 @@ +CREATE TYPE "public"."document_status" AS ENUM('Draft', 'Sent', 'Viewed', 'Signed');--> statement-breakpoint +CREATE TABLE "clients" ( + "id" text PRIMARY KEY NOT NULL, + "name" text NOT NULL, + "email" text NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL +); +--> statement-breakpoint +CREATE TABLE "documents" ( + "id" text PRIMARY KEY NOT NULL, + "name" text NOT NULL, + "client_id" text NOT NULL, + "status" "document_status" DEFAULT 'Draft' NOT NULL, + "sent_at" timestamp, + "created_at" timestamp DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "documents" ADD CONSTRAINT "documents_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action; \ No newline at end of file diff --git a/teressa-copeland-homes/drizzle/meta/0001_snapshot.json b/teressa-copeland-homes/drizzle/meta/0001_snapshot.json new file mode 100644 index 0000000..4a08e75 --- /dev/null +++ b/teressa-copeland-homes/drizzle/meta/0001_snapshot.json @@ -0,0 +1,187 @@ +{ + "id": "88e82a5b-fc38-4c78-b24f-2bcc020f874c", + "prevId": "67889008-a13f-4b7e-9a7e-87d0e0ca3fd4", + "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()" + } + }, + "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" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "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 b89f750..96ad59f 100644 --- a/teressa-copeland-homes/drizzle/meta/_journal.json +++ b/teressa-copeland-homes/drizzle/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1773948629637, "tag": "0000_milky_black_cat", "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1773958608977, + "tag": "0001_watery_blindfold", + "breakpoints": true } ] } \ No newline at end of file diff --git a/teressa-copeland-homes/src/lib/db/schema.ts b/teressa-copeland-homes/src/lib/db/schema.ts index d67261d..e3398c2 100644 --- a/teressa-copeland-homes/src/lib/db/schema.ts +++ b/teressa-copeland-homes/src/lib/db/schema.ts @@ -1,4 +1,4 @@ -import { pgTable, text, timestamp } from "drizzle-orm/pg-core"; +import { pgEnum, pgTable, text, timestamp } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()), @@ -6,3 +6,29 @@ export const users = pgTable("users", { passwordHash: text("password_hash").notNull(), createdAt: timestamp("created_at").defaultNow().notNull(), }); + +export const documentStatusEnum = pgEnum("document_status", [ + "Draft", + "Sent", + "Viewed", + "Signed", +]); + +export const clients = pgTable("clients", { + id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()), + name: text("name").notNull(), + email: text("email").notNull(), + 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(), + clientId: text("client_id") + .notNull() + .references(() => clients.id, { onDelete: "cascade" }), + status: documentStatusEnum("status").notNull().default("Draft"), + sentAt: timestamp("sent_at"), + createdAt: timestamp("created_at").defaultNow().notNull(), +});