001project_wildgrowth/backend/scripts/backfill-banner-watermark.ts

45 lines
1.3 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.

/**
* 一次性脚本:为「当前已在已启用运营位里的课程」批量设置水印为 globe.americas.fill
* 使用npx ts-node scripts/backfill-banner-watermark.ts
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const WATERMARK_ICON = 'globe.americas.fill';
async function main() {
// 1. 已启用、未删的运营位中的 courseId去重
const rows = await prisma.operationalBannerCourse.findMany({
where: {
banner: { deletedAt: null, isEnabled: true },
},
select: { courseId: true },
distinct: ['courseId'],
});
const courseIds = rows.map((r) => r.courseId);
if (courseIds.length === 0) {
console.log('[BackfillBannerWatermark] 当前没有运营位关联的课程,跳过');
return;
}
console.log(`[BackfillBannerWatermark] 运营位课程数: ${courseIds.length}, courseIds:`, courseIds);
// 2. 批量更新 watermark_icon
const result = await prisma.course.updateMany({
where: { id: { in: courseIds } },
data: { watermarkIcon: WATERMARK_ICON },
});
console.log(`[BackfillBannerWatermark] 已更新 ${result.count} 门课程的水印为 ${WATERMARK_ICON}`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => prisma.$disconnect());