This commit is contained in:
2025-07-19 12:21:46 +02:00
parent 12822dfdbf
commit 2e7957d0a0
86 changed files with 25573 additions and 0 deletions

31
scripts/clearStages.js Normal file
View File

@@ -0,0 +1,31 @@
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); });