chore(schema): organization 移除医院相关定义并留档数据清理脚本
医院数据统一走 hospital 集合后,organization 移除 hospital 枚举、 level 与就医信息字段(overview/photos/departments/doctors/guides)。 新增一次性清理脚本(删医院记录、删 2026-11 前订单)与只读体检脚本 (索引同步、孤儿引用、脏数据检查)。
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 一次性清理:删除 organization 集合里医院相关的记录。
|
||||
*
|
||||
* 医院基础信息已统一迁移到 hospital 集合(schema/hospital.js),
|
||||
* organization 集合不再维护医院数据;本脚本删除 type=hospital 的记录。
|
||||
*
|
||||
* 用法:在 api/health 下执行 `node scripts/delete_organization_hospitals.js`
|
||||
*/
|
||||
import { DBModel } from "../models/index.js";
|
||||
|
||||
DBModel.init();
|
||||
const conn = DBModel.dbConnection;
|
||||
|
||||
async function cleanup() {
|
||||
// 非医院记录(历史数据里可能有未填 type 的)统一保留,只删明确标记为医院的
|
||||
const filter = { type: "hospital" };
|
||||
const matched = await DBModel.Organization.countDocuments(filter).exec();
|
||||
const result = await DBModel.Organization.deleteMany(filter);
|
||||
|
||||
console.log(`deleted: matched=${matched}, deletedCount=${result.deletedCount}`);
|
||||
const remaining = await DBModel.Organization.countDocuments({}).exec();
|
||||
console.log(`remaining organizations: ${remaining}`);
|
||||
await conn.close();
|
||||
}
|
||||
|
||||
if (conn.readyState === 1) {
|
||||
cleanup().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
} else {
|
||||
conn.once("connected", () => {
|
||||
cleanup().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
conn.once("error", (error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user