Initial commit: EduBox V2 platform

This commit is contained in:
root
2026-06-06 19:55:41 +00:00
commit 0a73a70820
69 changed files with 5634 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Establishment {
id String @id @default(cuid())
name String
slug String @unique
createdAt DateTime @default(now())
subscription Subscription?
users User[]
classes Class[]
templates Template[]
}
model Subscription {
id String @id @default(cuid())
establishmentId String @unique
establishment Establishment @relation(fields: [establishmentId], references: [id], onDelete: Cascade)
plan String @default("trial")
status String @default("active")
expiresAt DateTime?
createdAt DateTime @default(now())
}
model User {
id String @id @default(cuid())
email String @unique
password String
role String
establishmentId String?
establishment Establishment? @relation(fields: [establishmentId], references: [id], onDelete: SetNull)
createdAt DateTime @default(now())
}
model Class {
id String @id @default(cuid())
establishmentId String
establishment Establishment @relation(fields: [establishmentId], references: [id], onDelete: Cascade)
name String
level String
createdAt DateTime @default(now())
students Student[]
}
model Student {
id String @id @default(cuid())
classId String
class Class @relation(fields: [classId], references: [id], onDelete: Cascade)
firstName String
lastName String
email String
activationCode String? @unique
createdAt DateTime @default(now())
nodes Node[]
}
model Node {
id String @id
studentId String?
student Student? @relation(fields: [studentId], references: [id], onDelete: SetNull)
tailscaleIp String?
status String @default("offline")
lastSeen DateTime?
createdAt DateTime @default(now())
instances Instance[]
}
model Instance {
id String @id @default(cuid())
nodeId String
node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
templateId String
template Template @relation(fields: [templateId], references: [id], onDelete: Restrict)
status String @default("stopped")
port Int
createdAt DateTime @default(now())
}
model Template {
id String @id @default(cuid())
name String
type String
dockerImage String
composeConfig String
isPublic Boolean @default(true)
establishmentId String?
establishment Establishment? @relation(fields: [establishmentId], references: [id], onDelete: Cascade)
createdBy String
createdAt DateTime @default(now())
instances Instance[]
}
+66
View File
@@ -0,0 +1,66 @@
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
const prisma = new PrismaClient();
async function main() {
const superadminEmail = process.env.SUPERADMIN_EMAIL || "admin@edudeploy.fr";
const superadminPassword = process.env.SUPERADMIN_PASSWORD || "CHANGE_ME";
const hashedPassword = await bcrypt.hash(superadminPassword, 12);
await prisma.user.upsert({
where: { email: superadminEmail },
update: {},
create: {
email: superadminEmail,
password: hashedPassword,
role: "superadmin",
},
});
const templates = [
{ name: "WordPress latest vierge", type: "wordpress", dockerImage: "wordpress:latest" },
{ name: "WordPress 6.7 vierge", type: "wordpress", dockerImage: "wordpress:6.7" },
{ name: "WordPress 6.4 vierge", type: "wordpress", dockerImage: "wordpress:6.4" },
{ name: "PrestaShop latest vierge", type: "prestashop", dockerImage: "prestashop/prestashop:latest" },
{ name: "PrestaShop 8.1 vierge", type: "prestashop", dockerImage: "prestashop/prestashop:8.1" },
];
for (const t of templates) {
const composeConfig = `services:
app:
image: ${t.dockerImage}
ports:
- "127.0.0.1:{PORT}:80"
environment:
INSTANCE_ID: {INSTANCE_ID}
restart: unless-stopped
`;
await prisma.template.upsert({
where: { id: `${t.type}-${t.dockerImage.replace(/[:\/]/g, "-")}` },
update: {},
create: {
id: `${t.type}-${t.dockerImage.replace(/[:\/]/g, "-")}`,
name: t.name,
type: t.type,
dockerImage: t.dockerImage,
composeConfig,
isPublic: true,
createdBy: "system",
},
});
}
console.log("Seed completed.");
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});