upd
This commit is contained in:
@@ -2,12 +2,16 @@ import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import { companiesTable } from "./companies";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { sessionsTable } from "./sessions";
|
||||
import { usersTable } from "./users";
|
||||
|
||||
export const clientsTable = pgTable("clients", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
fullname: varchar("fullname").notNull(),
|
||||
email: varchar("email").notNull(),
|
||||
phone: varchar("phone", { length: 15 }),
|
||||
name: varchar("name").notNull(),
|
||||
phone: varchar("phone", { length: 11 }).notNull(),
|
||||
email: varchar("email"),
|
||||
ownerId: uuid("owner_id")
|
||||
.notNull()
|
||||
.references(() => usersTable.id),
|
||||
companyId: uuid("company_id")
|
||||
.notNull()
|
||||
.references(() => companiesTable.id),
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
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";
|
||||
import { appsTable } from "./apps";
|
||||
|
||||
export const serversTable = pgTable("servers", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
hostname: varchar("hostname", { length: 15 }).notNull(),
|
||||
hostname: varchar("hostname", { length: 15 }).unique().notNull(),
|
||||
name: varchar("name").notNull(),
|
||||
location: varchar("location").notNull(),
|
||||
companyId: uuid("company_id")
|
||||
@@ -27,5 +27,5 @@ export const serversRelations = relations(serversTable, ({ one, many }) => ({
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
sessions: many(sessionsTable),
|
||||
actions: many(actionsTable),
|
||||
apps: many(appsTable),
|
||||
}));
|
||||
|
||||
+46
-29
@@ -1,39 +1,56 @@
|
||||
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import {
|
||||
pgTable,
|
||||
timestamp,
|
||||
uuid,
|
||||
varchar,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { companiesTable } from "./companies";
|
||||
import { usersTable } from "./users";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { serversTable } from "./servers";
|
||||
import { clientsTable } from "./clients";
|
||||
import { appsTable } from "./apps";
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
export const sessionsTable = pgTable("sessions", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
status: varchar("status", {
|
||||
enum: ["starting", "started", "restarting", "ending", "ended"],
|
||||
}),
|
||||
appId: uuid("app_id")
|
||||
.notNull()
|
||||
.references(() => appsTable.id),
|
||||
ownerId: uuid("owner_id")
|
||||
.notNull()
|
||||
.references(() => usersTable.id),
|
||||
serverId: uuid("server_id")
|
||||
.notNull()
|
||||
.references(() => serversTable.id),
|
||||
clientId: uuid("client_id")
|
||||
.notNull()
|
||||
.references(() => clientsTable.id),
|
||||
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 sessionsTable = pgTable(
|
||||
"sessions",
|
||||
{
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
status: varchar("status", {
|
||||
enum: ["starting", "started", "restarting", "ending", "ended"],
|
||||
})
|
||||
.notNull()
|
||||
.default("starting"),
|
||||
appId: uuid("app_id")
|
||||
.notNull()
|
||||
.references(() => appsTable.id),
|
||||
ownerId: uuid("owner_id")
|
||||
.notNull()
|
||||
.references(() => usersTable.id),
|
||||
serverId: uuid("server_id")
|
||||
.notNull()
|
||||
.references(() => serversTable.id),
|
||||
clientId: uuid("client_id")
|
||||
.notNull()
|
||||
.references(() => clientsTable.id),
|
||||
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()),
|
||||
},
|
||||
(table) => ({
|
||||
activeServerSessionIdx: uniqueIndex("active_server_session_idx")
|
||||
.on(table.serverId, table.status)
|
||||
.where(sql`${table.status} IN ('starting', 'started')`),
|
||||
})
|
||||
);
|
||||
|
||||
export const sessionsRelations = relations(sessionsTable, ({ one }) => ({
|
||||
owner: one(usersTable, {
|
||||
|
||||
Reference in New Issue
Block a user