32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
|
import { companiesTable } from "./companies";
|
|
import { actionsTable } from "./actions";
|
|
import { relations } from "drizzle-orm";
|
|
import { sessionsTable } from "./sessions";
|
|
|
|
export const serversTable = pgTable("servers", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
hostname: varchar("hostname", { length: 15 }).notNull(),
|
|
name: varchar("name").notNull(),
|
|
location: varchar("location").notNull(),
|
|
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 serversRelations = relations(serversTable, ({ one, many }) => ({
|
|
company: one(companiesTable, {
|
|
fields: [serversTable.companyId],
|
|
references: [companiesTable.id],
|
|
}),
|
|
sessions: many(sessionsTable),
|
|
actions: many(actionsTable),
|
|
}));
|