Skip to content

Commit 0f9927f

Browse files
committed
chore: Add task-existence precheck to avoid FK errors (#2734)
1 parent 1f4c53c commit 0f9927f

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

prisma/seed.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,30 @@ async function addContestTaskPairs() {
187187
for (const pair of contest_task_pairs) {
188188
contestTaskPairQueue.add(async () => {
189189
try {
190-
const registeredPair = await prisma.contestTaskPair.findUnique({
191-
where: {
192-
contestId_taskId: {
193-
contestId: pair.contest_id,
194-
taskId: pair.problem_id,
190+
const [registeredPair, registeredTask] = await Promise.all([
191+
prisma.contestTaskPair.findUnique({
192+
where: {
193+
contestId_taskId: {
194+
contestId: pair.contest_id,
195+
taskId: pair.problem_id,
196+
},
195197
},
196-
},
197-
});
198+
}),
199+
prisma.task.findUnique({
200+
where: { task_id: pair.problem_id },
201+
}),
202+
]);
198203

199-
if (!registeredPair) {
204+
if (!registeredTask) {
205+
console.warn(
206+
'Skipped contest task pair due to missing task:',
207+
pair.problem_id,
208+
'for contest',
209+
pair.contest_id,
210+
'index',
211+
pair.problem_index,
212+
);
213+
} else if (!registeredPair) {
200214
await addContestTaskPair(pair, contestTaskPairFactory);
201215
console.log(
202216
'contest_id:',

prisma/tasks.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5296,6 +5296,13 @@ export const tasks = [
52965296
title: '078. Easy Graph Problem(★2)',
52975297
grade: 'Q5',
52985298
},
5299+
{
5300+
id: 'typical90_s',
5301+
contest_id: 'typical90',
5302+
problem_index: '019',
5303+
name: 'Pick Two(★6)',
5304+
title: '019. Pick Two(★6)',
5305+
},
52995306
{
53005307
id: 'typical90_n',
53015308
contest_id: 'typical90',

0 commit comments

Comments
 (0)