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

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-02-11 15:26:03 +08:00
/**
* 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());