import bcrypt from "bcryptjs"; import { PrismaClient, Role, Currency, PaymentProvider } from "@prisma/client"; const prisma = new PrismaClient(); async function main() { const adminEmail = process.env.ADMIN_EMAIL ?? "admin@proxpanel.local"; const adminPassword = process.env.ADMIN_PASSWORD ?? "ChangeMe123!"; const password_hash = await bcrypt.hash(adminPassword, 12); const tenant = await prisma.tenant.upsert({ where: { slug: "default-tenant" }, update: {}, create: { name: "Default Tenant", slug: "default-tenant", owner_email: adminEmail, currency: Currency.NGN, payment_provider: PaymentProvider.PAYSTACK } }); await prisma.user.upsert({ where: { email: adminEmail }, update: { role: Role.SUPER_ADMIN, password_hash, tenant_id: tenant.id }, create: { email: adminEmail, full_name: "System Administrator", password_hash, role: Role.SUPER_ADMIN, tenant_id: tenant.id } }); await prisma.setting.upsert({ where: { key: "proxmox" }, update: {}, create: { key: "proxmox", type: "PROXMOX", value: { host: "", port: 8006, username: "root@pam", token_id: "", token_secret: "", verify_ssl: true } } }); await prisma.setting.upsert({ where: { key: "payment" }, update: {}, create: { key: "payment", type: "PAYMENT", value: { default_provider: "paystack", paystack_public: "", paystack_secret: "", flutterwave_public: "", flutterwave_secret: "", flutterwave_webhook_hash: "", callback_url: "" } } }); await prisma.setting.upsert({ where: { key: "provisioning" }, update: {}, create: { key: "provisioning", type: "GENERAL", value: { min_vmid: 100 } } }); await prisma.setting.upsert({ where: { key: "backup" }, update: {}, create: { key: "backup", type: "GENERAL", value: { default_source: "local", default_storage: "local-lvm", max_restore_file_count: 100, pbs_enabled: false, pbs_host: "", pbs_datastore: "", pbs_namespace: "", pbs_verify_ssl: true } } }); await prisma.billingPlan.upsert({ where: { slug: "starter" }, update: {}, create: { name: "Starter", slug: "starter", description: "Entry plan for lightweight VM workloads", price_monthly: 12000, price_hourly: 12000 / 720, currency: Currency.NGN, cpu_cores: 2, ram_mb: 4096, disk_gb: 60, bandwidth_gb: 2000, features: ["basic-support", "daily-backups"] } }); const ubuntuTemplate = await prisma.appTemplate.upsert({ where: { slug: "ubuntu-22-04-golden" }, update: {}, create: { name: "Ubuntu 22.04 Golden", slug: "ubuntu-22-04-golden", template_type: "KVM_TEMPLATE", virtualization_type: "QEMU", source: "local:vztmpl/ubuntu-22.04-golden.qcow2", description: "Baseline hardened Ubuntu template", metadata: { os_family: "linux", os_version: "22.04" } } }); const webGroup = await prisma.applicationGroup.upsert({ where: { slug: "web-workloads" }, update: {}, create: { name: "Web Workloads", slug: "web-workloads", description: "HTTP-facing application services" } }); await prisma.applicationGroupTemplate.upsert({ where: { group_id_template_id: { group_id: webGroup.id, template_id: ubuntuTemplate.id } }, update: {}, create: { group_id: webGroup.id, template_id: ubuntuTemplate.id, priority: 10 } }); await prisma.backupPolicy.upsert({ where: { id: "default-tenant-backup-policy" }, update: {}, create: { id: "default-tenant-backup-policy", tenant_id: tenant.id, max_files: 25, max_total_size_mb: 102400, max_protected_files: 5, allow_file_restore: true, allow_cross_vm_restore: true, allow_pbs_restore: true } }); } main() .then(async () => { await prisma.$disconnect(); }) .catch(async (error) => { // eslint-disable-next-line no-console console.error("Seed failed:", error); await prisma.$disconnect(); process.exit(1); });