Reconcile schema with migrations and fix failed migration

- Align schema.prisma with add_15_features migration (15 discrepancies):
  nullability, column names, PKs, missing/extra columns, onDelete behavior
- Make universal_apply_programid migration idempotent for safe re-execution
- Add reconciliation migration for missing FKs and indexes
- Fix message.ts and mentor.ts to match corrected schema field names

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-08 14:37:32 +01:00
parent 04d0deced1
commit e0e4cb2a32
18 changed files with 1174 additions and 353 deletions

View File

@@ -2,6 +2,8 @@
import { BookOpen, ClipboardList, GitCompare, Home } from 'lucide-react'
import { RoleNav, type NavItem, type RoleNavUser } from '@/components/layouts/role-nav'
import { trpc } from '@/lib/trpc/client'
import { Badge } from '@/components/ui/badge'
const navigation: NavItem[] = [
{
@@ -30,6 +32,38 @@ interface JuryNavProps {
user: RoleNavUser
}
function RemainingBadge() {
const { data: assignments } = trpc.assignment.myAssignments.useQuery(
{},
{ refetchInterval: 60000 }
)
if (!assignments) return null
const now = new Date()
const remaining = (assignments as Array<{
round: { status: string; votingStartAt: Date | null; votingEndAt: Date | null }
evaluation: { status: string } | null
}>).filter((a) => {
const isActive =
a.round.status === 'ACTIVE' &&
a.round.votingStartAt &&
a.round.votingEndAt &&
new Date(a.round.votingStartAt) <= now &&
new Date(a.round.votingEndAt) >= now
const isIncomplete = !a.evaluation || a.evaluation.status !== 'SUBMITTED'
return isActive && isIncomplete
}).length
if (remaining === 0) return null
return (
<Badge variant="secondary" className="text-xs font-medium">
{remaining} remaining
</Badge>
)
}
export function JuryNav({ user }: JuryNavProps) {
return (
<RoleNav
@@ -37,6 +71,7 @@ export function JuryNav({ user }: JuryNavProps) {
roleName="Jury"
user={user}
basePath="/jury"
statusBadge={<RemainingBadge />}
/>
)
}

View File

@@ -1,6 +1,6 @@
'use client'
import { useState } from 'react'
import { useState, useEffect } from 'react'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { signOut } from 'next-auth/react'
@@ -17,7 +17,8 @@ import {
} from '@/components/ui/dropdown-menu'
import type { Route } from 'next'
import type { LucideIcon } from 'lucide-react'
import { LogOut, Menu, Settings, User, X } from 'lucide-react'
import { LogOut, Menu, Moon, Settings, Sun, User, X } from 'lucide-react'
import { useTheme } from 'next-themes'
import { Logo } from '@/components/shared/logo'
import { NotificationBell } from '@/components/shared/notification-bell'
@@ -38,23 +39,31 @@ type RoleNavProps = {
user: RoleNavUser
/** The base path for the role (e.g., '/jury', '/mentor', '/observer'). Used for active state detection on the dashboard link. */
basePath: string
/** Optional status badge displayed next to the logo (e.g., remaining evaluations count) */
statusBadge?: React.ReactNode
}
function isNavItemActive(pathname: string, href: string, basePath: string): boolean {
return pathname === href || (href !== basePath && pathname.startsWith(href))
}
export function RoleNav({ navigation, roleName, user, basePath }: RoleNavProps) {
export function RoleNav({ navigation, roleName, user, basePath, statusBadge }: RoleNavProps) {
const pathname = usePathname()
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false)
const { data: avatarUrl } = trpc.avatar.getUrl.useQuery()
const { theme, setTheme } = useTheme()
const [mounted, setMounted] = useState(false)
useEffect(() => setMounted(true), [])
return (
<header className="sticky top-0 z-40 border-b bg-card">
<div className="container-app">
<div className="flex h-16 items-center justify-between">
{/* Logo */}
<Logo showText textSuffix={roleName} />
<div className="flex items-center gap-3">
<Logo showText textSuffix={roleName} />
{statusBadge}
</div>
{/* Desktop nav */}
<nav className="hidden md:flex items-center gap-1">
@@ -80,6 +89,20 @@ export function RoleNav({ navigation, roleName, user, basePath }: RoleNavProps)
{/* User menu & mobile toggle */}
<div className="flex items-center gap-2">
{mounted && (
<Button
variant="ghost"
size="icon"
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
aria-label="Toggle theme"
>
{theme === 'dark' ? (
<Sun className="h-5 w-5" />
) : (
<Moon className="h-5 w-5" />
)}
</Button>
)}
<NotificationBell />
<DropdownMenu>
<DropdownMenuTrigger asChild>

View File

@@ -1,6 +1,6 @@
'use client'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import Link from 'next/link'
import type { Route } from 'next'
import { usePathname } from 'next/navigation'
@@ -250,6 +250,14 @@ export function NotificationBell() {
onSuccess: () => refetch(),
})
// Auto-mark all notifications as read when popover opens
useEffect(() => {
if (open && (countData ?? 0) > 0) {
markAllAsReadMutation.mutate()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open])
const unreadCount = countData ?? 0
const notifications = notificationData?.notifications ?? []