upd
This commit is contained in:
+25
-7
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
pgTable,
|
||||
primaryKey,
|
||||
timestamp,
|
||||
uniqueIndex,
|
||||
uuid,
|
||||
@@ -15,9 +16,6 @@ export const appsTable = pgTable(
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
name: varchar("name").notNull(),
|
||||
fileName: varchar("filename").notNull(),
|
||||
serverId: uuid("server_id")
|
||||
.notNull()
|
||||
.references(() => serversTable.id, { onDelete: "cascade" }),
|
||||
companyId: uuid("company_id")
|
||||
.notNull()
|
||||
.references(() => companiesTable.id, { onDelete: "cascade" }),
|
||||
@@ -31,19 +29,39 @@ export const appsTable = pgTable(
|
||||
},
|
||||
(table) => ({
|
||||
uniqueFileNameServerId: uniqueIndex("unique_file_name_server_id").on(
|
||||
table.fileName,
|
||||
table.serverId
|
||||
table.fileName
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
export const appsRelations = relations(appsTable, ({ one }) => ({
|
||||
export const appsRelations = relations(appsTable, ({ one, many }) => ({
|
||||
company: one(companiesTable, {
|
||||
fields: [appsTable.companyId],
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
servers: many(appsToServers),
|
||||
}));
|
||||
|
||||
export const appsToServers = pgTable(
|
||||
"apps_to_servers",
|
||||
{
|
||||
appId: uuid("app_id")
|
||||
.notNull()
|
||||
.references(() => appsTable.id),
|
||||
serverId: uuid("server_id")
|
||||
.notNull()
|
||||
.references(() => serversTable.id),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.appId, t.serverId] })]
|
||||
);
|
||||
|
||||
export const appsToServersRelations = relations(appsToServers, ({ one }) => ({
|
||||
app: one(appsTable, {
|
||||
fields: [appsToServers.appId],
|
||||
references: [appsTable.id],
|
||||
}),
|
||||
server: one(serversTable, {
|
||||
fields: [appsTable.serverId],
|
||||
fields: [appsToServers.serverId],
|
||||
references: [serversTable.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
+41
-23
@@ -1,29 +1,47 @@
|
||||
import { pgTable, timestamp, uuid, varchar, inet } from "drizzle-orm/pg-core";
|
||||
import {
|
||||
pgTable,
|
||||
timestamp,
|
||||
uuid,
|
||||
varchar,
|
||||
inet,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { companiesTable } from "./companies";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { sessionsTable } from "./sessions";
|
||||
import { appsTable } from "./apps";
|
||||
import { appsToServers } 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 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").notNull(),
|
||||
},
|
||||
(t) => ({
|
||||
uniqueHostnameCompanyId: uniqueIndex("unique_hostname_company_id").on(
|
||||
t.hostname,
|
||||
t.companyId
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
export const serversRelations = relations(serversTable, ({ one, many }) => ({
|
||||
company: one(companiesTable, {
|
||||
@@ -31,5 +49,5 @@ export const serversRelations = relations(serversTable, ({ one, many }) => ({
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
sessions: many(sessionsTable),
|
||||
apps: many(appsTable),
|
||||
apps: many(appsToServers),
|
||||
}));
|
||||
|
||||
+7
-1
@@ -8,7 +8,7 @@ import cron from "node-cron";
|
||||
import { exec, execFile } from "child_process";
|
||||
import { createHmac } from "crypto";
|
||||
import got from "got";
|
||||
import { readdirSync } from "fs";
|
||||
import { readdirSync, readFile, readFileSync } from "fs";
|
||||
import treeKill from "tree-kill";
|
||||
|
||||
type Session = typeof sessionsTable.$inferSelect & {
|
||||
@@ -296,4 +296,10 @@ serve({
|
||||
fetch: () => new Response("venom"),
|
||||
});
|
||||
|
||||
async function runSummarization() {
|
||||
try {
|
||||
const res = execFile("C://neuro/summary.exe");
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
console.log("Server is running at http://localhost:3001");
|
||||
|
||||
Reference in New Issue
Block a user