- 更新种子脚本:10大赛道×51个子板块,热门排序 - 新增清理脚本:删除所有非10赛道旧板块 - 重做侧边栏:仿工具模块的二级平铺导航,带搜索过滤 - 新增排行组件:本月活跃+积分总排行移至右侧栏 - 调整页面布局:左导航(220px)+中内容+右指南/排行(280px) - TypeScript编译零错误通过
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
import { PrismaClient } from "@prisma/client";
|
|
import { PrismaMariaDb } from "@prisma/adapter-mariadb";
|
|
import "dotenv/config";
|
|
|
|
const base = process.env.DATABASE_URL.replace("mysql://", "mariadb://");
|
|
const sep = base.includes("?") ? "&" : "?";
|
|
const connectionString = `${base}${sep}connection_limit=5&pool_timeout=10`;
|
|
const adapter = new PrismaMariaDb(connectionString);
|
|
const prisma = new PrismaClient({ adapter });
|
|
|
|
const INDUSTRY_SLUGS = [
|
|
"ecommerce", "ai-tech", "content", "finance", "cross-border",
|
|
"real-estate", "food", "local-life", "health", "education",
|
|
];
|
|
|
|
const INDUSTRY_CHILD_SLUGS = [
|
|
"ec-platform", "ec-livestream", "ec-private", "ec-group", "ec-dtc", "ec-supply",
|
|
"ai-tools-app", "ai-startup-forum", "ai-saas", "ai-hardware", "ai-llm",
|
|
"ct-short-video", "ct-live", "ct-writing", "ct-mcn", "ct-podcast",
|
|
"fi-stock", "fi-crypto", "fi-insurance", "fi-pe", "fi-forex",
|
|
"cb-ecommerce", "cb-factory", "cb-logistics", "cb-payment", "cb-brand",
|
|
"re-residential", "re-commercial", "re-renovation", "re-property",
|
|
"fd-restaurant", "fd-tea", "fd-prepared", "fd-supply", "fd-delivery",
|
|
"ll-beauty", "ll-fitness", "ll-pet", "ll-housekeeping", "ll-repair", "ll-edu-local",
|
|
"hl-cosmetic", "hl-wellness", "hl-elderly", "hl-rehab", "hl-mental",
|
|
"edu-skills", "edu-knowledge", "edu-abroad", "edu-corporate", "edu-k12",
|
|
];
|
|
|
|
const KEEP_SLUGS = new Set(["industry", ...INDUSTRY_SLUGS, ...INDUSTRY_CHILD_SLUGS]);
|
|
|
|
async function main() {
|
|
console.log("Cleaning up old forum categories...");
|
|
|
|
const allCategories = await prisma.forumCategory.findMany({
|
|
include: { _count: { select: { topics: true } } },
|
|
});
|
|
|
|
let deleted = 0;
|
|
let kept = 0;
|
|
|
|
for (const cat of allCategories) {
|
|
if (KEEP_SLUGS.has(cat.slug)) {
|
|
kept++;
|
|
continue;
|
|
}
|
|
|
|
const topicsCount = cat._count.topics;
|
|
console.log(` Deleting: ${cat.slug} "${cat.name}" (${topicsCount} topics)`);
|
|
|
|
if (topicsCount > 0) {
|
|
await prisma.forumTopic.deleteMany({ where: { categoryId: cat.id } });
|
|
}
|
|
|
|
await prisma.forumCategory.updateMany({
|
|
where: { parentId: cat.id },
|
|
data: { parentId: null },
|
|
});
|
|
|
|
await prisma.forumCategory.delete({ where: { id: cat.id } });
|
|
deleted++;
|
|
}
|
|
|
|
console.log(`Done: ${deleted} deleted, ${kept} kept.`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
}); |