feat(03-01): add clients and documents tables to Drizzle schema
- Add pgEnum import and documentStatusEnum (Draft, Sent, Viewed, Signed)
- Add clients table (id, name, email, createdAt, updatedAt)
- Add documents table (id, name, clientId FK, status enum, sentAt, createdAt)
- Generate migration 0001_watery_blindfold.sql and apply to local PostgreSQL
2026-03-19 16:17:26 -06:00
|
|
|
import { pgEnum, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
2026-03-19 21:44:17 -06:00
|
|
|
import { relations } from "drizzle-orm";
|
2026-03-19 13:30:52 -06:00
|
|
|
|
|
|
|
|
export const users = pgTable("users", {
|
|
|
|
|
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
|
|
|
email: text("email").notNull().unique(),
|
|
|
|
|
passwordHash: text("password_hash").notNull(),
|
|
|
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
|
|
|
});
|
feat(03-01): add clients and documents tables to Drizzle schema
- Add pgEnum import and documentStatusEnum (Draft, Sent, Viewed, Signed)
- Add clients table (id, name, email, createdAt, updatedAt)
- Add documents table (id, name, clientId FK, status enum, sentAt, createdAt)
- Generate migration 0001_watery_blindfold.sql and apply to local PostgreSQL
2026-03-19 16:17:26 -06:00
|
|
|
|
|
|
|
|
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(),
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-19 21:32:30 -06:00
|
|
|
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(),
|
|
|
|
|
});
|
|
|
|
|
|
feat(03-01): add clients and documents tables to Drizzle schema
- Add pgEnum import and documentStatusEnum (Draft, Sent, Viewed, Signed)
- Add clients table (id, name, email, createdAt, updatedAt)
- Add documents table (id, name, clientId FK, status enum, sentAt, createdAt)
- Generate migration 0001_watery_blindfold.sql and apply to local PostgreSQL
2026-03-19 16:17:26 -06:00
|
|
|
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(),
|
2026-03-19 21:32:30 -06:00
|
|
|
formTemplateId: text("form_template_id").references(() => formTemplates.id),
|
|
|
|
|
filePath: text("file_path"),
|
feat(03-01): add clients and documents tables to Drizzle schema
- Add pgEnum import and documentStatusEnum (Draft, Sent, Viewed, Signed)
- Add clients table (id, name, email, createdAt, updatedAt)
- Add documents table (id, name, clientId FK, status enum, sentAt, createdAt)
- Generate migration 0001_watery_blindfold.sql and apply to local PostgreSQL
2026-03-19 16:17:26 -06:00
|
|
|
});
|
2026-03-19 21:44:17 -06:00
|
|
|
|
|
|
|
|
export const documentsRelations = relations(documents, ({ one }) => ({
|
|
|
|
|
client: one(clients, { fields: [documents.clientId], references: [clients.id] }),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
export const clientsRelations = relations(clients, ({ many }) => ({
|
|
|
|
|
documents: many(documents),
|
|
|
|
|
}));
|