36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { pgTable, timestamp, uuid, varchar, inet } from "drizzle-orm/pg-core";
|
|
import { companiesTable } from "./companies";
|
|
import { relations } from "drizzle-orm";
|
|
import { sessionsTable } from "./sessions";
|
|
import { appsTable } from "./apps";
|
|
|
|
export const serversTable = pgTable("servers", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
hostname: varchar("hostname", { length: 15 }).notNull(),
|
|
name: varchar("name").notNull().default("Новый стол"),
|
|
description: varchar("description").notNull(),
|
|
companyId: uuid("company_id")
|
|
.notNull()
|
|
.references(() => companiesTable.id, {
|
|
onDelete: "cascade",
|
|
}),
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow(),
|
|
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow()
|
|
.$onUpdate(() => new Date()),
|
|
status: varchar("status", { enum: ["online", "offline"] }).default("online"),
|
|
ipAddress: inet("ip_address"),
|
|
});
|
|
|
|
export const serversRelations = relations(serversTable, ({ one, many }) => ({
|
|
company: one(companiesTable, {
|
|
fields: [serversTable.companyId],
|
|
references: [companiesTable.id],
|
|
}),
|
|
sessions: many(sessionsTable),
|
|
apps: many(appsTable),
|
|
}));
|