Files
digicraft-be/scripts/legacy/emergency_json_fix.ts
Fahri Can Seçer 80dcf4d04a
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
main
2026-02-05 01:29:22 +03:00

60 lines
2.0 KiB
TypeScript

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();