haixunMaster/scripts/clear-workspace-data.ts

38 lines
1.4 KiB
TypeScript
Raw Permalink 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.

/**
* 清空經營工作區資料,保留 User / Session / Account / Setting / AutomationRule。
* 用法npx tsx scripts/clear-workspace-data.ts
*/
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
const counts = {
outreachDrafts: await prisma.outreachDraft.deleteMany(),
outreachTargets: await prisma.outreachTarget.deleteMany(),
replyDrafts: await prisma.replyDraft.deleteMany(),
inboundReplies: await prisma.inboundReply.deleteMany(),
performanceSnapshots: await prisma.performanceSnapshot.deleteMany(),
published: await prisma.published.deleteMany(),
drafts: await prisma.draft.deleteMany(),
replies: await prisma.reply.deleteMany(),
scans: await prisma.scan.deleteMany(),
topics: await prisma.topic.deleteMany(),
productProfiles: await prisma.productProfile.deleteMany(),
backgroundJobs: await prisma.backgroundJob.deleteMany(),
actionLogs: await prisma.actionLog.deleteMany(),
};
console.log("已清理工作區資料:");
for (const [table, result] of Object.entries(counts)) {
console.log(` ${table}: ${result.count}`);
}
console.log("\n保留使用者、登入 session、經營帳號、系統設定、自動化規則、Threads 連線。");
}
main()
.catch((err) => {
console.error(err);
process.exit(1);
})
.finally(() => prisma.$disconnect());