/** * 一次性脚本:按新 6 色池(品牌蓝 + 多邻国绿/紫/红/黄/橙)重算并更新所有课程的 theme_color * 使用:npx ts-node scripts/backfill-theme-colors.ts */ import { PrismaClient } from '@prisma/client'; import { generateThemeColor } from '../src/utils/courseTheme'; const prisma = new PrismaClient(); async function main() { const courses = await prisma.course.findMany({ select: { id: true }, where: { deletedAt: null }, }); if (courses.length === 0) { console.log('[BackfillThemeColors] 没有课程,跳过'); return; } console.log(`[BackfillThemeColors] 共 ${courses.length} 门课程,开始按 courseId 哈希重算 theme_color...`); let updated = 0; for (const c of courses) { const themeColor = generateThemeColor(c.id); await prisma.course.update({ where: { id: c.id }, data: { themeColor }, }); updated++; } console.log(`[BackfillThemeColors] 已更新 ${updated} 门课程的 theme_color(6 色池:品牌蓝 + 多邻国绿/紫/红/黄/橙)`); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(() => prisma.$disconnect());