| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const { PrismaClient } = require('@prisma/client');
- const prisma = new PrismaClient();
- async function updateAllSubsections() {
- console.log('\n📝 开始更新所有小节内容为"你好"...\n');
-
- // 查找所有level=3的小节
- const subsections = await prisma.bookChapter.findMany({
- where: {
- level: 3
- },
- select: {
- id: true,
- title: true,
- bookId: true,
- }
- });
-
- console.log(`找到 ${subsections.length} 个小节\n`);
-
- let updatedCount = 0;
- let failedCount = 0;
-
- // 批量更新
- for (const sub of subsections) {
- try {
- await prisma.bookChapter.update({
- where: { id: sub.id },
- data: {
- content: '你好',
- contentStatus: 'completed',
- wordCount: 2,
- }
- });
- updatedCount++;
-
- if (updatedCount % 50 === 0) {
- console.log(`已更新 ${updatedCount}/${subsections.length} 个小节...`);
- }
- } catch (error) {
- failedCount++;
- console.error(`更新失败: 小节ID=${sub.id}, ${error.message}`);
- }
- }
-
- console.log(`\n✅ 更新完成!`);
- console.log(` 成功: ${updatedCount} 个`);
- console.log(` 失败: ${failedCount} 个`);
- console.log(` 总计: ${subsections.length} 个\n`);
-
- await prisma.$disconnect();
- }
- updateAllSubsections().catch(console.error);
|