All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 4m24s
清空 votes / fan_supports / daily_quota / sign_ins / risk_logs / snapshots 并 reset artists.vote_count=0 / current_rank=null。保留 users / artists / activity_config。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
// 清空投票相关测试数据,准备重新测试。
|
|
//
|
|
// 清:votes / fan_supports / daily_quota / sign_ins / risk_logs / ranking_snapshots
|
|
// reset:artists.vote_count = 0, artists.current_rank = null
|
|
// 保留:users / artists 配置 / activity_config / invitations
|
|
import { PrismaClient } from "@prisma/client";
|
|
const prisma = new PrismaClient({ log: ["error"] });
|
|
|
|
console.log("=== 清空投票测试数据 ===\n");
|
|
|
|
// 跑前 snapshot
|
|
const before = {
|
|
votes: await prisma.vote.count(),
|
|
fanSupports: await prisma.fanSupport.count(),
|
|
dailyQuotas: await prisma.dailyQuota.count(),
|
|
signIns: await prisma.signIn.count(),
|
|
riskLogs: await prisma.riskLog.count(),
|
|
snapshots: await prisma.rankingSnapshot.count(),
|
|
artistsWithVotes: await prisma.artist.count({ where: { voteCount: { gt: 0 } } }),
|
|
};
|
|
console.log("清前:", before);
|
|
|
|
await prisma.$transaction(
|
|
async (tx) => {
|
|
await tx.vote.deleteMany({});
|
|
await tx.fanSupport.deleteMany({});
|
|
await tx.dailyQuota.deleteMany({});
|
|
await tx.signIn.deleteMany({});
|
|
await tx.riskLog.deleteMany({});
|
|
await tx.rankingSnapshot.deleteMany({});
|
|
// reset artists 缓存
|
|
await tx.artist.updateMany({
|
|
data: { voteCount: 0, currentRank: null },
|
|
});
|
|
},
|
|
{ timeout: 30000 },
|
|
);
|
|
|
|
const after = {
|
|
votes: await prisma.vote.count(),
|
|
fanSupports: await prisma.fanSupport.count(),
|
|
dailyQuotas: await prisma.dailyQuota.count(),
|
|
signIns: await prisma.signIn.count(),
|
|
riskLogs: await prisma.riskLog.count(),
|
|
snapshots: await prisma.rankingSnapshot.count(),
|
|
artistsWithVotes: await prisma.artist.count({ where: { voteCount: { gt: 0 } } }),
|
|
};
|
|
console.log("\n清后:", after);
|
|
|
|
// 同时确认保留了什么
|
|
const preserved = {
|
|
users: await prisma.user.count(),
|
|
artists: await prisma.artist.count(),
|
|
activityConfig: await prisma.activityConfig.count(),
|
|
};
|
|
console.log("保留:", preserved);
|
|
|
|
await prisma.$disconnect();
|
|
console.log("\n✓ 完成");
|