gongxiangp2/scripts/list-non-migrated-materials.ts
chenpei 4dba93c4e5 feat: 完成任务-详情素材迁移到新逻辑
- 迁移57个老素材到新逻辑(本地zip + S3预览图)
- 优化文件命名:SPU_作者_店铺_类型.zip
- PSD文件单独存储,不打包进all.zip
- 修复下载接口,优先使用本地zip文件
- 修复预览图重复问题
- 添加迁移脚本和验证脚本
- 更新文档和迁移计划

迁移统计:
- 总素材数:77个
- 成功迁移:57个
- 新逻辑上传:18个
- 空记录:2个
2026-01-21 10:16:28 +08:00

89 lines
2.6 KiB
TypeScript
Raw 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.

/**
* 列出未被本次迁移的素材
*/
import { PrismaClient } from '@prisma/client';
import { readFile } from 'fs/promises';
import path from 'path';
const prisma = new PrismaClient();
async function main() {
// 1. 读取所有迁移日志,获取本次迁移的素材ID
const migratedIds = new Set<string>();
// 读取最近的迁移日志(从今天开始)
const logFiles = [
'logs/migration-log-1768923605237.json', // XG0176
'logs/migration-log-1768923722086.json', // 第一批
'logs/migration-log-1768923840136.json', // 第一批
'logs/migration-log-1768923958151.json', // 第二批
'logs/migration-log-1768924161945.json', // 第三批
'logs/migration-log-1768924240279.json', // 第四批
'logs/migration-log-1768924412848.json', // 验证
'logs/migration-log-1768924519354.json', // 验证
'logs/migration-log-1768924819982.json', // 新一批1
'logs/migration-log-1768925113364.json', // 新一批2
'logs/migration-log-1768925294759.json', // 新一批3
'logs/migration-log-1768925358913.json', // 新一批4
];
for (const logFile of logFiles) {
try {
const content = await readFile(logFile, 'utf-8');
const logs = JSON.parse(content);
for (const log of logs) {
if (log.status === 'success') {
migratedIds.add(log.materialId);
}
}
} catch (error) {
// 文件不存在,跳过
}
}
console.log(`本次迁移成功的素材数量: ${migratedIds.size}`);
console.log('');
// 2. 查询所有素材
const allMaterials = await prisma.material.findMany({
where: {
materialType: '任务-详情',
deletedAt: null,
},
select: {
id: true,
productModel: true,
taskNo: true,
createdAt: true,
user: {
select: {
realName: true,
username: true,
},
},
},
orderBy: { createdAt: 'desc' },
});
console.log(`总素材数: ${allMaterials.length}`);
console.log('');
// 3. 找出未被本次迁移的素材
const nonMigratedMaterials = allMaterials.filter(m => !migratedIds.has(m.id));
console.log(`未被本次迁移的素材数量: ${nonMigratedMaterials.length}`);
console.log('');
console.log('未被本次迁移的素材列表:');
console.log('='.repeat(80));
for (const material of nonMigratedMaterials) {
const authorName = material.user?.realName || material.user?.username || '未知';
console.log(`SPU: ${material.productModel.padEnd(20)} | 作者: ${authorName.padEnd(15)} | 任务号: ${material.taskNo || '无'}`);
}
await prisma.$disconnect();
}
main();