This commit is contained in:
2025-06-17 12:27:30 +05:00
parent 050ba744c7
commit 67f6283ea4
14 changed files with 141 additions and 93 deletions
+8 -6
View File
@@ -13,6 +13,7 @@ import { serversTable } from "./servers";
import { clientsTable } from "./clients";
import { appsTable } from "./apps";
import { sql } from "drizzle-orm";
import { commentsTable } from "./comments";
export const sessionsTable = pgTable(
"sessions",
@@ -26,19 +27,19 @@ export const sessionsTable = pgTable(
pid: integer("pid"),
appId: uuid("app_id")
.notNull()
.references(() => appsTable.id),
.references(() => appsTable.id, { onDelete: "cascade" }),
ownerId: uuid("owner_id")
.notNull()
.references(() => usersTable.id),
.references(() => usersTable.id, { onDelete: "cascade" }),
serverId: uuid("server_id")
.notNull()
.references(() => serversTable.id),
.references(() => serversTable.id, { onDelete: "cascade" }),
clientId: uuid("client_id")
.notNull()
.references(() => clientsTable.id),
.references(() => clientsTable.id, { onDelete: "cascade" }),
companyId: uuid("company_id")
.notNull()
.references(() => companiesTable.id),
.references(() => companiesTable.id, { onDelete: "cascade" }),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
@@ -54,7 +55,7 @@ export const sessionsTable = pgTable(
})
);
export const sessionsRelations = relations(sessionsTable, ({ one }) => ({
export const sessionsRelations = relations(sessionsTable, ({ one, many }) => ({
owner: one(usersTable, {
fields: [sessionsTable.ownerId],
references: [usersTable.id],
@@ -75,4 +76,5 @@ export const sessionsRelations = relations(sessionsTable, ({ one }) => ({
fields: [sessionsTable.appId],
references: [appsTable.id],
}),
comments: many(commentsTable),
}));