30 lines
971 B
TypeScript
30 lines
971 B
TypeScript
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
|
import { companiesTable } from "./companies";
|
|
import { relations } from "drizzle-orm";
|
|
import { sessionsTable } from "./sessions";
|
|
|
|
export const clientsTable = pgTable("clients", {
|
|
id: uuid("id").defaultRandom().primaryKey(),
|
|
fullname: varchar("fullname").notNull(),
|
|
email: varchar("email").notNull(),
|
|
phone: varchar("phone", { length: 15 }),
|
|
companyId: uuid("company_id")
|
|
.notNull()
|
|
.references(() => companiesTable.id),
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow(),
|
|
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow()
|
|
.$onUpdate(() => new Date()),
|
|
});
|
|
|
|
export const clientsRelations = relations(clientsTable, ({ one, many }) => ({
|
|
company: one(companiesTable, {
|
|
fields: [clientsTable.companyId],
|
|
references: [companiesTable.id],
|
|
}),
|
|
sessions: many(sessionsTable),
|
|
}));
|