refactor: 奖品命名去除"纪念章"字样
奖品不一定是纪念章(可能是实物、折扣券、体验券等), 统一改为"XX · 专属奖品"。新增一次性数据清理脚本, 同步改写存量 Prize 与 Redemption 历史快照。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
73
packages/server/src/scripts/rename-prize-names.ts
Normal file
73
packages/server/src/scripts/rename-prize-names.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { prisma } from "@stamp/shared";
|
||||||
|
|
||||||
|
const OLD_SUFFIX = "· 纪念章";
|
||||||
|
const NEW_SUFFIX = "· 专属奖品";
|
||||||
|
const OLD_DESC_RE = /^在「(.+)」集到的专属纪念奖品$/;
|
||||||
|
const NEW_DESC = (brand: string) => `在「${brand}」可兑换的专属奖品`;
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const apply = process.argv.includes("--apply");
|
||||||
|
|
||||||
|
const prizes = await prisma.prize.findMany();
|
||||||
|
const prizeNameHits = prizes.filter((p) => p.name.endsWith(OLD_SUFFIX));
|
||||||
|
const prizeDescHits = prizes.filter((p) => p.description && OLD_DESC_RE.test(p.description));
|
||||||
|
|
||||||
|
const redemptions = await prisma.redemption.findMany();
|
||||||
|
const redemptionHits = redemptions.filter((r) => r.prizeName.endsWith(OLD_SUFFIX));
|
||||||
|
|
||||||
|
console.log(`=== Prize.name (${prizeNameHits.length}) ===`);
|
||||||
|
prizeNameHits.slice(0, 20).forEach((p) => {
|
||||||
|
const next = p.name.slice(0, -OLD_SUFFIX.length) + NEW_SUFFIX;
|
||||||
|
console.log(` "${p.name}" → "${next}"`);
|
||||||
|
});
|
||||||
|
if (prizeNameHits.length > 20) console.log(` ...共 ${prizeNameHits.length} 条`);
|
||||||
|
|
||||||
|
console.log(`\n=== Prize.description (${prizeDescHits.length}) ===`);
|
||||||
|
prizeDescHits.slice(0, 20).forEach((p) => {
|
||||||
|
const m = p.description!.match(OLD_DESC_RE)!;
|
||||||
|
console.log(` "${p.description}" → "${NEW_DESC(m[1])}"`);
|
||||||
|
});
|
||||||
|
if (prizeDescHits.length > 20) console.log(` ...共 ${prizeDescHits.length} 条`);
|
||||||
|
|
||||||
|
console.log(`\n=== Redemption.prizeName (${redemptionHits.length}) ===`);
|
||||||
|
redemptionHits.slice(0, 20).forEach((r) => {
|
||||||
|
const next = r.prizeName.slice(0, -OLD_SUFFIX.length) + NEW_SUFFIX;
|
||||||
|
console.log(` "${r.prizeName}" → "${next}"`);
|
||||||
|
});
|
||||||
|
if (redemptionHits.length > 20) console.log(` ...共 ${redemptionHits.length} 条`);
|
||||||
|
|
||||||
|
const total = prizeNameHits.length + prizeDescHits.length + redemptionHits.length;
|
||||||
|
if (total === 0) {
|
||||||
|
console.log("\n✓ 没有需要替换的记录。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!apply) {
|
||||||
|
console.log(`\nDRY RUN — 共 ${total} 条待改。传入 --apply 执行写入。`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`\n正在写入...`);
|
||||||
|
await prisma.$transaction(async (tx) => {
|
||||||
|
for (const p of prizeNameHits) {
|
||||||
|
const next = p.name.slice(0, -OLD_SUFFIX.length) + NEW_SUFFIX;
|
||||||
|
await tx.prize.update({ where: { id: p.id }, data: { name: next } });
|
||||||
|
}
|
||||||
|
for (const p of prizeDescHits) {
|
||||||
|
const m = p.description!.match(OLD_DESC_RE)!;
|
||||||
|
await tx.prize.update({ where: { id: p.id }, data: { description: NEW_DESC(m[1]) } });
|
||||||
|
}
|
||||||
|
for (const r of redemptionHits) {
|
||||||
|
const next = r.prizeName.slice(0, -OLD_SUFFIX.length) + NEW_SUFFIX;
|
||||||
|
await tx.redemption.update({ where: { id: r.id }, data: { prizeName: next } });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(`\n完成。已更新 ${total} 条。`);
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
})
|
||||||
|
.finally(() => prisma.$disconnect());
|
||||||
@@ -36,8 +36,8 @@ async function seed() {
|
|||||||
sortOrder: idx + 1,
|
sortOrder: idx + 1,
|
||||||
prize: {
|
prize: {
|
||||||
create: {
|
create: {
|
||||||
name: `${s.name} · 纪念章`,
|
name: `${s.name} · 专属奖品`,
|
||||||
description: `在「${s.name}」集到的专属纪念奖品`,
|
description: `在「${s.name}」可兑换的专属奖品`,
|
||||||
stock: 100,
|
stock: 100,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ export default function StampForm({ open, id, onClose, onSaved }: Props) {
|
|||||||
<input
|
<input
|
||||||
value={prizeName}
|
value={prizeName}
|
||||||
onChange={(e) => setPrizeName(e.target.value)}
|
onChange={(e) => setPrizeName(e.target.value)}
|
||||||
placeholder="如:朝天宫纪念书签"
|
placeholder="如:品牌 8 折券 / 定制书签"
|
||||||
className={fieldCls}
|
className={fieldCls}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
|||||||
Reference in New Issue
Block a user