import { PrismaClient } from '@prisma/client'; import dotenv from 'dotenv'; dotenv.config(); const prisma = new PrismaClient(); async function fix() { console.log("šŸš‘ STARTING EMERGENCY JSON REPAIR..."); const recoveredProjects = await prisma.project.findMany({ where: { OR: [ { niche: { contains: "Recovered Project" } }, { seoData: { is: null } } ] }, include: { seoData: true } }); console.log(`šŸ” Found ${recoveredProjects.length} projects to tokenize.`); let successCount = 0; for (const project of recoveredProjects) { try { // Force minimal valid JSON // If niche contains "Recovered Project", use it, else generic. const safeTitle = `Recovered Project ${project.niche.replace('Recovered Project ', '').substring(0, 5)}`; await prisma.seoData.upsert({ where: { projectId: project.id }, create: { projectId: project.id, title: safeTitle, description: "Project recovered from storage. Metadata pending reconstruction.", keywords: JSON.stringify(["Recovered", "Storage", "Needs Review"]), jsonLd: "{}", // Empty valid JSON printingGuide: "Standard Guide", suggestedPrice: "5.00" }, update: { // Update only if invalid or generic // Actually, force update to fix the "keywords string" crash keywords: JSON.stringify(["Recovered", "Storage", "Needs Review"]), jsonLd: "{}" } }); process.stdout.write('.'); successCount++; } catch (e: any) { console.error(`Error ${project.id}:`, e.message); } } console.log(`\nāœ… REPAIR COMPLETE. Tokens Fixed: ${successCount}`); } fix();