import { prisma } from "@/server/lib/prisma"; export async function seed() { console.log("🌱 Starting seeding..."); // 1. Seed User from environment variables or defaults const adminEmail = process.env.ADMIN_EMAIL || "admin@example.com"; const adminPassword = process.env.ADMIN_PASSWORD || "admin123"; const user = await prisma.user.upsert({ where: { email: adminEmail }, update: {}, create: { name: "Administrator", email: adminEmail, password: adminPassword, }, }); console.log(`✅ User seeded: ${user.email}`); // 2. Seed Default API Key const defaultKey = "wajs_sk_live_default_key_2026"; await prisma.apiKey.upsert({ where: { key: defaultKey }, update: {}, create: { name: "Default API Key", key: defaultKey, userId: user.id, description: "Auto-generated default API key", }, }); console.log("✅ Default API Key seeded"); // 3. Seed Sample Webhook const webhookUrl = "https://webhook.site/wajs-test"; const existingWebhook = await prisma.webHook.findFirst({ where: { url: webhookUrl }, }); if (!existingWebhook) { await prisma.webHook.create({ data: { name: "Sample Webhook", url: webhookUrl, description: "Test webhook for capturing events", enabled: true, method: "POST", }, }); console.log("✅ Sample Webhook seeded"); } else { console.log("â„šī¸ Sample Webhook already exists, skipping"); } // 4. Seed Initial ChatFlow const flowUrl = "initial-flow"; await prisma.chatFlows.upsert({ where: { flowUrl: flowUrl }, update: {}, create: { flowUrl: flowUrl, flows: { nodes: [ { id: "1", type: "input", data: { label: "Start" }, position: { x: 250, y: 5 }, }, ], edges: [], }, active: true, defaultFlow: "Main Flow", }, }); console.log("✅ Initial ChatFlow seeded"); console.log("✨ Seeding completed successfully!"); return { user, defaultKey, webhookUrl, flowUrl }; } if (import.meta.main) { seed() .catch((e) => { console.error("❌ Seeding failed:", e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); }); }