import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
  console.log('开始更新 BookChapter 表状态...');

  // 先统计当前状态
  const statusStats = await prisma.bookChapter.groupBy({
    by: ['status'],
    _count: {
      id: true,
    },
  });

  console.log('更新前状态统计:', statusStats);

  // 更新所有记录状态为 completed
  const result = await prisma.bookChapter.updateMany({
    data: {
      status: 'completed',
    },
  });

  console.log(`更新完成，共更新 ${result.count} 条记录`);

  // 验证更新结果
  const afterStats = await prisma.bookChapter.groupBy({
    by: ['status'],
    _count: {
      id: true,
    },
  });

  console.log('更新后状态统计:', afterStats);
}

main()
  .catch((e) => {
    console.error('更新失败:', e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
