31 lines
1.4 KiB
JavaScript
31 lines
1.4 KiB
JavaScript
const { PrismaClient } = require('../generated/prisma');
|
|
|
|
async function main() {
|
|
const prisma = new PrismaClient();
|
|
// Find all single elimination stages
|
|
const singleElimStages = await prisma.tournamentStage.findMany({ where: { type: 'SINGLE_ELIM' } });
|
|
if (!singleElimStages.length) {
|
|
console.log('No single elimination stages found.');
|
|
await prisma.$disconnect();
|
|
return;
|
|
}
|
|
let totalDeletedMatches = 0;
|
|
let totalDeletedResults = 0;
|
|
for (const stage of singleElimStages) {
|
|
// Find all matches for this stage
|
|
const matches = await prisma.match.findMany({ where: { stageId: stage.id } });
|
|
const matchIds = matches.map(m => m.id);
|
|
// Delete all results for these matches
|
|
const deletedResults = await prisma.result.deleteMany({ where: { matchId: { in: matchIds } } });
|
|
// Delete all matches for this stage
|
|
const deletedMatches = await prisma.match.deleteMany({ where: { stageId: stage.id } });
|
|
// Delete the stage itself
|
|
await prisma.tournamentStage.delete({ where: { id: stage.id } });
|
|
totalDeletedMatches += deletedMatches.count;
|
|
totalDeletedResults += deletedResults.count;
|
|
}
|
|
console.log(`Deleted ${singleElimStages.length} SINGLE_ELIM stages, ${totalDeletedMatches} matches, and ${totalDeletedResults} results.`);
|
|
await prisma.$disconnect();
|
|
}
|
|
|
|
main().catch(e => { console.error(e); process.exit(1); });
|