001project_wildgrowth/backend/scripts/backfill-theme-colors.ts

43 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 一次性脚本:按新 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_color6 色池:品牌蓝 + 多邻国绿/紫/红/黄/橙)`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => prisma.$disconnect());