95 lines
3.7 KiB
TypeScript
95 lines
3.7 KiB
TypeScript
import { pgTable, text, timestamp, boolean, uuid, integer, customType } from "drizzle-orm/pg-core"
|
|
|
|
const bytea = customType<{ data: Buffer }>({
|
|
dataType() {
|
|
return "bytea"
|
|
},
|
|
})
|
|
|
|
export const users = pgTable("users", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
email: text("email").notNull().unique(),
|
|
name: text("name").notNull(),
|
|
role: text("role").notNull(),
|
|
passwordHash: text("password_hash").notNull(),
|
|
createdAt: timestamp("created_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const customers = pgTable("customers", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
name: text("name").notNull(),
|
|
tags: text("tags").array().notNull().default([]),
|
|
active: boolean("active").notNull().default(true),
|
|
createdAt: timestamp("created_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const projects = pgTable("projects", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
name: text("name").notNull(),
|
|
customerId: uuid("customer_id").notNull().references(() => customers.id, { onDelete: "cascade" }),
|
|
active: boolean("active").notNull().default(true),
|
|
createdAt: timestamp("created_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const projectTemplates = pgTable("project_templates", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
name: text("name").notNull(),
|
|
defaultBillable: boolean("default_billable").notNull().default(true),
|
|
estimatedHours: integer("estimated_hours"),
|
|
createdAt: timestamp("created_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const timeEntries = pgTable("time_entries", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
projectId: uuid("project_id").references(() => projects.id, { onDelete: "cascade" }),
|
|
description: text("description").notNull(),
|
|
notes: text("notes"),
|
|
startTime: timestamp("start_time").notNull(),
|
|
endTime: timestamp("end_time"),
|
|
createdAt: timestamp("created_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const appSettings = pgTable("app_settings", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
workspaceName: text("workspace_name").notNull().default("EmberClone"),
|
|
defaultBillable: boolean("default_billable").notNull().default(true),
|
|
weekStart: integer("week_start").notNull().default(1),
|
|
roundingMinutes: integer("rounding_minutes").notNull().default(0),
|
|
updatedAt: timestamp("updated_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const auditLog = pgTable("audit_log", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
userId: uuid("user_id").references(() => users.id),
|
|
action: text("action").notNull(),
|
|
resourceType: text("resource_type"),
|
|
resourceId: text("resource_id"),
|
|
metadata: text("metadata"),
|
|
createdAt: timestamp("created_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const documents = pgTable("documents", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
userId: uuid("user_id").references(() => users.id),
|
|
filename: text("filename").notNull(),
|
|
contentType: text("content_type").notNull(),
|
|
sizeBytes: integer("size_bytes").notNull(),
|
|
content: bytea("content"),
|
|
createdAt: timestamp("created_at").notNull().defaultNow()
|
|
})
|
|
|
|
export const timeEntryAttachments = pgTable("time_entry_attachments", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
entryId: uuid("entry_id").notNull().references(() => timeEntries.id, { onDelete: "cascade" }),
|
|
documentId: uuid("document_id").notNull().references(() => documents.id, { onDelete: "cascade" }),
|
|
})
|
|
|
|
export const webhooks = pgTable("webhooks", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
url: text("url").notNull(),
|
|
event: text("event").notNull(),
|
|
active: boolean("active").notNull().default(true),
|
|
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
createdBy: uuid("created_by").references(() => users.id)
|
|
}) |