fix(categories): 分类名去括号——同步入库整段删除括号段
左侧分类树/官网分类名的括号段(型号限定词(JSA002)与内容性括号 (黑+卡其)/(短裤 & 长裤))整段删除。分类名每小时被 SDS 同步覆盖, 清洗落在 syncCategories 入库路径(cleanCategoryDisplayName,款号 token 保留,剥空守卫),另附幂等存量脚本 fix:category-names。 已执行:V1/V2 各 33 条分类名去括号,复跑幂等 0。注意 api 容器重建 部署前旧镜像的下一轮同步会把名称写回原文,部署后自动恢复干净。 Tests: api 23 suites/206 passed(含新增 category-name.spec 7 例),tsc clean
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 存量修复脚本(幂等):分类名去括号 —— 删除所有括号段(型号限定词/内容性括号,
|
||||
* 整段删除)。分类名每小时被 SDS 同步覆盖,清洗已落在 syncCategories 入库路径;
|
||||
* 本脚本用于部署后立即生效(不等下一轮同步)或修人工建的历史分类。
|
||||
*
|
||||
* 运行:
|
||||
* pnpm --filter @inkreach/api fix:category-names # dry-run,只打印清单
|
||||
* pnpm --filter @inkreach/api fix:category-names -- --apply # 实际写库
|
||||
*/
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
import { cleanCategoryDisplayName } from '../src/sync/sync.service';
|
||||
|
||||
async function main() {
|
||||
const apply = process.argv.includes('--apply');
|
||||
const prisma = new PrismaService();
|
||||
await prisma.onModuleInit();
|
||||
|
||||
const rows = await prisma.category.findMany({
|
||||
select: { id: true, categoryName: true },
|
||||
orderBy: { id: 'asc' },
|
||||
});
|
||||
const renames = rows
|
||||
.map((row) => ({
|
||||
id: row.id,
|
||||
from: row.categoryName,
|
||||
to: cleanCategoryDisplayName(row.categoryName) ?? row.categoryName,
|
||||
}))
|
||||
.filter((r) => r.from !== r.to);
|
||||
|
||||
if (apply && renames.length > 0) {
|
||||
await prisma.$transaction(
|
||||
renames.map((r) =>
|
||||
prisma.category.update({
|
||||
where: { id: r.id },
|
||||
data: { categoryName: r.to },
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
const mode = apply ? 'APPLIED' : 'DRY-RUN(未写库,加 --apply 执行)';
|
||||
console.log(`[fix:category-names] ${mode} renamed=${renames.length}`);
|
||||
for (const r of renames) {
|
||||
console.log(` #${r.id} ${r.from} -> ${r.to}`);
|
||||
}
|
||||
await prisma.onModuleDestroy();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user