Completed matches scheduling

This commit is contained in:
2025-07-20 01:08:51 +02:00
parent 99e8b4ce55
commit f2efe52fcb
10 changed files with 554 additions and 368 deletions

View File

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