const { PrismaClient } = require('../generated/prisma'); async function main() { const prisma = new PrismaClient(); // Find the round robin stage(s) const rrStages = await prisma.tournamentStage.findMany({ where: { type: 'ROUND_ROBIN' } }); const rrStageIds = rrStages.map(s => s.id); if (rrStageIds.length === 0) { console.log('No round robin stage found.'); await prisma.$disconnect(); return; } // Find all matches for these stages const rrMatches = await prisma.match.findMany({ where: { stageId: { in: rrStageIds } } }); const rrMatchIds = rrMatches.map(m => m.id); // Delete results for these matches await prisma.result.deleteMany({ where: { matchId: { in: rrMatchIds } } }); // Delete matches await prisma.match.deleteMany({ where: { id: { in: rrMatchIds } } }); // Delete the round robin stages await prisma.tournamentStage.deleteMany({ where: { id: { in: rrStageIds } } }); console.log(`Deleted ${rrStages.length} round robin stage(s), ${rrMatches.length} matches, and their results.`); await prisma.$disconnect(); } main().catch(e => { console.error(e); process.exit(1); });