upd
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import * as schema from "./schema/index";
|
||||
|
||||
const client = postgres(process.env.DB_URL);
|
||||
const db = drizzle({ client, schema });
|
||||
|
||||
export default db;
|
||||
@@ -0,0 +1,25 @@
|
||||
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import { serversTable } from "./servers";
|
||||
import { relations } from "drizzle-orm";
|
||||
|
||||
export const actionsTable = pgTable("actions", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
name: varchar("name").notNull(),
|
||||
serverId: uuid("server_id")
|
||||
.notNull()
|
||||
.references(() => serversTable.id),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date()),
|
||||
});
|
||||
|
||||
export const actionsRelations = relations(actionsTable, ({ one }) => ({
|
||||
server: one(serversTable, {
|
||||
fields: [actionsTable.serverId],
|
||||
references: [serversTable.id],
|
||||
}),
|
||||
}));
|
||||
@@ -0,0 +1,26 @@
|
||||
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import { companiesTable } from "./companies";
|
||||
import { relations } from "drizzle-orm";
|
||||
|
||||
export const appsTable = pgTable("apps", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
name: varchar("name").notNull(),
|
||||
fileName: varchar("filename").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 appsRelations = relations(appsTable, ({ one }) => ({
|
||||
company: one(companiesTable, {
|
||||
fields: [appsTable.companyId],
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
}));
|
||||
@@ -0,0 +1,29 @@
|
||||
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import { companiesTable } from "./companies";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { sessionsTable } from "./sessions";
|
||||
|
||||
export const clientsTable = pgTable("clients", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
fullname: varchar("fullname").notNull(),
|
||||
email: varchar("email").notNull(),
|
||||
phone: varchar("phone", { length: 15 }),
|
||||
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 clientsRelations = relations(clientsTable, ({ one, many }) => ({
|
||||
company: one(companiesTable, {
|
||||
fields: [clientsTable.companyId],
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
sessions: many(sessionsTable),
|
||||
}));
|
||||
@@ -0,0 +1,24 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import { usersTable } from "./users";
|
||||
import { appsTable } from "./apps";
|
||||
import { serversTable } from "./servers";
|
||||
|
||||
export const companiesTable = pgTable("companies", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
name: varchar("name").notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date()),
|
||||
});
|
||||
|
||||
export const companiesRelations = relations(companiesTable, ({ many }) => ({
|
||||
users: many(usersTable),
|
||||
servers: many(serversTable),
|
||||
apps: many(appsTable),
|
||||
// actions: many(actionsTable),
|
||||
}));
|
||||
@@ -0,0 +1,8 @@
|
||||
export * from "./users";
|
||||
export * from "./tokens";
|
||||
export * from "./companies";
|
||||
export * from "./servers";
|
||||
export * from "./sessions";
|
||||
export * from "./clients";
|
||||
export * from "./apps";
|
||||
export * from "./actions";
|
||||
@@ -0,0 +1,31 @@
|
||||
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),
|
||||
}));
|
||||
@@ -0,0 +1,59 @@
|
||||
import { pgTable, timestamp, uuid, varchar } 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";
|
||||
|
||||
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 sessionsRelations = relations(sessionsTable, ({ one }) => ({
|
||||
owner: one(usersTable, {
|
||||
fields: [sessionsTable.ownerId],
|
||||
references: [usersTable.id],
|
||||
}),
|
||||
server: one(serversTable, {
|
||||
fields: [sessionsTable.serverId],
|
||||
references: [serversTable.id],
|
||||
}),
|
||||
company: one(companiesTable, {
|
||||
fields: [sessionsTable.companyId],
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
client: one(clientsTable, {
|
||||
fields: [sessionsTable.clientId],
|
||||
references: [clientsTable.id],
|
||||
}),
|
||||
app: one(appsTable, {
|
||||
fields: [sessionsTable.appId],
|
||||
references: [appsTable.id],
|
||||
}),
|
||||
}));
|
||||
@@ -0,0 +1,25 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
||||
import { usersTable } from "./users";
|
||||
|
||||
export const tokensTable = pgTable("tokens", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
token: text("token").notNull(),
|
||||
userId: uuid("user_id")
|
||||
.notNull()
|
||||
.references(() => usersTable.id, { onDelete: "cascade" }),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date()),
|
||||
});
|
||||
|
||||
export const tokensRelations = relations(tokensTable, ({ one }) => ({
|
||||
user: one(usersTable, {
|
||||
fields: [tokensTable.userId],
|
||||
references: [usersTable.id],
|
||||
}),
|
||||
}));
|
||||
@@ -0,0 +1,30 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { pgTable, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import { tokensTable } from "./tokens";
|
||||
import { companiesTable } from "./companies";
|
||||
|
||||
export const usersTable = pgTable("users", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
fullname: text("fullname"),
|
||||
email: varchar("email").unique().notNull(),
|
||||
password: varchar("password", { length: 72 }).notNull(),
|
||||
// roles: text("roles").array().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 usersRelations = relations(usersTable, ({ one, many }) => ({
|
||||
company: one(companiesTable, {
|
||||
fields: [usersTable.companyId],
|
||||
references: [companiesTable.id],
|
||||
}),
|
||||
tokens: many(tokensTable),
|
||||
}));
|
||||
Reference in New Issue
Block a user