204 lines
5.8 KiB
Plaintext
204 lines
5.8 KiB
Plaintext
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "mysql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// This is your Prisma schema file,
|
|
model Tariff {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
price Float
|
|
description String?
|
|
createdAt DateTime @default(now())
|
|
servers Server[]
|
|
|
|
@@map("tariff")
|
|
}
|
|
|
|
|
|
|
|
model OperatingSystem {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
type String // linux, windows, etc
|
|
template String? // путь к шаблону для контейнера
|
|
createdAt DateTime @default(now())
|
|
servers Server[]
|
|
|
|
@@map("operatingsystem")
|
|
}
|
|
|
|
model Server {
|
|
id Int @id @default(autoincrement())
|
|
userId Int
|
|
tariffId Int
|
|
osId Int
|
|
status String @default("creating") // creating, running, stopped, suspended, error
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
user User @relation(fields: [userId], references: [id])
|
|
tariff Tariff @relation(fields: [tariffId], references: [id])
|
|
os OperatingSystem @relation(fields: [osId], references: [id])
|
|
|
|
// Proxmox данные
|
|
node String?
|
|
diskTemplate String?
|
|
proxmoxId Int?
|
|
|
|
// Сетевые настройки
|
|
ipAddress String? // Локальный IP адрес
|
|
macAddress String? // MAC адрес
|
|
|
|
// Доступы
|
|
rootPassword String? // Зашифрованный root пароль
|
|
sshPublicKey String? // SSH публичный ключ (опционально)
|
|
|
|
// Мониторинг
|
|
lastPing DateTime?
|
|
cpuUsage Float? @default(0)
|
|
memoryUsage Float? @default(0)
|
|
diskUsage Float? @default(0)
|
|
networkIn Float? @default(0)
|
|
networkOut Float? @default(0)
|
|
|
|
// Автоматические платежи
|
|
nextPaymentDate DateTime? // Дата следующего списания
|
|
autoRenew Boolean @default(true) // Автопродление
|
|
|
|
payments Payment[]
|
|
|
|
@@map("server")
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
username String
|
|
email String @unique
|
|
password String
|
|
createdAt DateTime @default(now())
|
|
plans Plan[] @relation("UserPlans")
|
|
operator Int @default(0)
|
|
isAdmin Boolean @default(false) // Админские права
|
|
tickets Ticket[] @relation("UserTickets")
|
|
responses Response[] @relation("OperatorResponses")
|
|
checks Check[] @relation("UserChecks")
|
|
balance Float @default(0)
|
|
servers Server[]
|
|
notifications Notification[]
|
|
payments Payment[]
|
|
transactions Transaction[] // История всех транзакций
|
|
|
|
@@map("user")
|
|
}
|
|
|
|
model Check {
|
|
id Int @id @default(autoincrement())
|
|
userId Int
|
|
amount Float
|
|
status String @default("pending") // pending, approved, rejected
|
|
fileUrl String
|
|
createdAt DateTime @default(now())
|
|
user User @relation("UserChecks", fields: [userId], references: [id])
|
|
|
|
@@map("check")
|
|
}
|
|
|
|
model Plan {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
price Float
|
|
description String?
|
|
isCustom Boolean @default(false)
|
|
createdAt DateTime @default(now())
|
|
userId Int
|
|
owner User @relation("UserPlans", fields: [userId], references: [id])
|
|
services Service[] @relation("PlanServices")
|
|
|
|
@@map("plan")
|
|
}
|
|
|
|
model Service {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
price Float
|
|
planId Int?
|
|
plan Plan? @relation("PlanServices", fields: [planId], references: [id])
|
|
|
|
@@map("service")
|
|
}
|
|
|
|
model Ticket {
|
|
id Int @id @default(autoincrement())
|
|
title String
|
|
message String
|
|
userId Int
|
|
status String @default("open")
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
responses Response[] @relation("TicketResponses")
|
|
user User? @relation("UserTickets", fields: [userId], references: [id])
|
|
|
|
@@map("ticket")
|
|
}
|
|
|
|
model Response {
|
|
id Int @id @default(autoincrement())
|
|
ticketId Int
|
|
operatorId Int
|
|
message String
|
|
createdAt DateTime @default(now())
|
|
ticket Ticket @relation("TicketResponses", fields: [ticketId], references: [id])
|
|
operator User @relation("OperatorResponses", fields: [operatorId], references: [id])
|
|
|
|
@@map("response")
|
|
|
|
|
|
}
|
|
model Notification {
|
|
id Int @id @default(autoincrement())
|
|
user User @relation(fields: [userId], references: [id])
|
|
userId Int
|
|
title String
|
|
message String
|
|
createdAt DateTime @default(now())
|
|
|
|
@@map("notification")
|
|
}
|
|
|
|
// Автоматические платежи за серверы
|
|
model Payment {
|
|
id Int @id @default(autoincrement())
|
|
userId Int
|
|
serverId Int
|
|
amount Float
|
|
status String @default("pending") // pending, success, failed
|
|
type String // subscription, manual
|
|
createdAt DateTime @default(now())
|
|
processedAt DateTime?
|
|
user User @relation(fields: [userId], references: [id])
|
|
server Server @relation(fields: [serverId], references: [id], onDelete: Cascade)
|
|
|
|
@@map("payment")
|
|
}
|
|
|
|
// История всех транзакций (пополнения, списания, возвраты)
|
|
model Transaction {
|
|
id Int @id @default(autoincrement())
|
|
userId Int
|
|
amount Float
|
|
type String // deposit (пополнение), withdrawal (списание), refund (возврат)
|
|
description String
|
|
balanceBefore Float
|
|
balanceAfter Float
|
|
adminId Int? // ID админа, если операция выполнена админом
|
|
createdAt DateTime @default(now())
|
|
user User @relation(fields: [userId], references: [id])
|
|
|
|
@@map("transaction")
|
|
} |