refactor: tech debt batch 2 — drop dead models, stale columns, schema cleanup

Schema:
- Drop 4 dead models: OverrideAction, NotificationPolicy, AssignmentException, AdvancementRule
- Drop 2 dead enums: OverrideReasonCode, AdvancementRuleType
- Drop 3 stale columns: Project.roundId, ConflictOfInterest.roundId, Evaluation.version
- Remove 3 back-relation fields from User, Assignment, Round

Code:
- Fix 6 COI queries in assignment.ts + 1 in juror-reassignment.ts
  (roundId filter → assignment.roundId after column drop)
- Remove orphaned Project.roundId write in project.ts createProject
- Remove advancementRules include from round.ts getById
- Remove AdvancementRule from RoundWithRelations type
- Clean up seed.ts (remove advancement rule seeding)
- Clean up tests/helpers.ts (remove dead model cleanup)
- Add TODO comments on user delete mutations (FK violation risk)

Migration: 20260308000000_drop_dead_models_and_stale_columns

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 12:35:23 +01:00
parent 1356809cb1
commit 1c78ecf21d
10 changed files with 49 additions and 126 deletions

View File

@@ -119,7 +119,7 @@ async function runAIAssignmentJob(jobId: string, roundId: string, userId: string
// Query COI records for this round to exclude conflicted juror-project pairs
const coiRecords = await prisma.conflictOfInterest.findMany({
where: {
roundId,
assignment: { roundId },
hasConflict: true,
},
select: { userId: true, projectId: true },
@@ -1665,7 +1665,7 @@ export const assignmentRouter = router({
for (const a of existingAssignments) currentLoads.set(a.userId, (currentLoads.get(a.userId) ?? 0) + 1)
const coiRecords = await ctx.prisma.conflictOfInterest.findMany({
where: { roundId: input.roundId, hasConflict: true, userId: { in: candidateIds } },
where: { assignment: { roundId: input.roundId }, hasConflict: true, userId: { in: candidateIds } },
select: { userId: true, projectId: true },
})
const coiPairs = new Set(coiRecords.map((c) => `${c.userId}:${c.projectId}`))
@@ -1911,7 +1911,7 @@ export const assignmentRouter = router({
const coiRecords = await ctx.prisma.conflictOfInterest.findMany({
where: {
roundId: input.roundId,
assignment: { roundId: input.roundId },
hasConflict: true,
userId: { in: candidateIds },
},
@@ -2026,7 +2026,7 @@ export const assignmentRouter = router({
const coiRecords = await ctx.prisma.conflictOfInterest.findMany({
where: {
roundId: input.roundId,
assignment: { roundId: input.roundId },
hasConflict: true,
userId: { in: destinationIds },
},
@@ -2367,7 +2367,7 @@ export const assignmentRouter = router({
const coiRecords = await ctx.prisma.conflictOfInterest.findMany({
where: {
roundId: input.roundId,
assignment: { roundId: input.roundId },
hasConflict: true,
userId: { in: candidateIds },
},

View File

@@ -638,10 +638,6 @@ export const projectRouter = router({
})
if (input.roundId) {
await tx.project.update({
where: { id: created.id },
data: { roundId: input.roundId },
})
await tx.projectRoundState.create({
data: {
projectId: created.id,

View File

@@ -120,7 +120,6 @@ export const roundRouter = router({
submissionWindow: {
include: { fileRequirements: true },
},
advancementRules: { orderBy: { sortOrder: 'asc' } },
visibleSubmissionWindows: {
include: { submissionWindow: true },
},

View File

@@ -206,7 +206,10 @@ export const userRouter = router({
})
}
// Delete user
// TODO: This delete will fail with a FK violation for any user with activity
// (COI declarations, mentor assignments, messages, evaluations, etc.).
// A proper purge flow with pre-deletion cleanup or soft-delete is needed
// before hard-delete can work reliably for active users.
await ctx.prisma.user.delete({
where: { id: ctx.user.id },
})
@@ -657,6 +660,10 @@ export const userRouter = router({
select: { email: true },
})
// TODO: This delete will fail with a FK violation for any user with activity
// (COI declarations, mentor assignments, messages, evaluations, etc.).
// A proper purge flow with pre-deletion cleanup or soft-delete is needed
// before hard-delete can work reliably for active users.
const user = await ctx.prisma.user.delete({
where: { id: input.id },
})

View File

@@ -357,7 +357,7 @@ export async function reassignDroppedJurorAssignments(params: {
const coiRecords = await prisma.conflictOfInterest.findMany({
where: {
roundId: params.roundId,
assignment: { roundId: params.roundId },
hasConflict: true,
userId: { in: candidateIds },
},

View File

@@ -5,7 +5,6 @@ import type {
JuryGroupMember,
SubmissionWindow,
SubmissionFileRequirement,
AdvancementRule,
RoundSubmissionVisibility,
ProjectRoundState,
DeliberationSession,
@@ -36,7 +35,6 @@ export type RoundSummary = Pick<
export type RoundWithRelations = Round & {
juryGroup: (JuryGroup & { members: JuryGroupMember[] }) | null
submissionWindow: (SubmissionWindow & { fileRequirements: SubmissionFileRequirement[] }) | null
advancementRules: AdvancementRule[]
visibleSubmissionWindows: (RoundSubmissionVisibility & { submissionWindow: SubmissionWindow })[]
_count?: { projectRoundStates: number; assignments: number }
}