/home/techb158/cosmic-risk.abdallabala.com/prisma
Edit: /home/techb158/cosmic-risk.abdallabala.com/prisma/cleanup-dups.js (1914B)
const{PrismaClient}=require('@prisma/client');const p=new PrismaClient();
(async()=>{
const proj = await p.project.findFirst({ where: { name: 'Retail Customer Support GenAI Assistant' } });
if (proj) {
// Delete duplicate projects and their related data
const dups = await p.project.findMany({ where: { name: 'Retail Customer Support GenAI Assistant', id: { not: proj.id } } });
for (const d of dups) {
await p.gateCriterion.deleteMany({ where: { gate: { projectId: d.id } } }).catch(()=>{});
await p.gateEvaluation.deleteMany({ where: { projectId: d.id } }).catch(()=>{});
await p.modelMetric.deleteMany({ where: { experiment: { projectId: d.id } } }).catch(()=>{});
await p.experiment.deleteMany({ where: { projectId: d.id } }).catch(()=>{});
await p.indicator.deleteMany({ where: { projectId: d.id } }).catch(()=>{});
await p.evidence.deleteMany({ where: { mitigation: { risk: { projectId: d.id } } } }).catch(()=>{});
await p.mitigation.deleteMany({ where: { risk: { projectId: d.id } } }).catch(()=>{});
await p.risk.deleteMany({ where: { projectId: d.id } }).catch(()=>{});
await p.lifecyclePhase.deleteMany({ where: { projectId: d.id } }).catch(()=>{});
await p.reportExport.deleteMany({ where: { projectId: d.id } }).catch(()=>{});
await p.auditEvent.deleteMany({ where: { projectId: d.id } }).catch(()=>{});
await p.project.delete({ where: { id: d.id } }).catch(()=>{});
console.log('Cleaned duplicate:', d.id);
}
}
console.log('Projects now:', await p.project.count());
console.log('Risks now:', await p.risk.count());
console.log('Mitigations now:', await p.mitigation.count());
console.log('Indicators now:', await p.indicator.count());
console.log('Experiments now:', await p.experiment.count());
console.log('Gates now:', await p.gateEvaluation.count());
await p.$disconnect()
})()