core: add history for psdoc,ddoc,drdoc

This commit is contained in:
undefined committed 2020-10-05 20:58:18 +08:00
1 parent c49970f4be
commit b8c316c44b
12 files changed
+70 -32

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
/* eslint-disable no-await-in-loop */
import * as domain from './model/domain';
import * as document from './model/document';
type UpgradeScript = () => Promise<void>;
const scripts: UpgradeScript[] = [
// Init
async function _0_1() {
const ddoc = await domain.get('system');
if (!ddoc) await domain.add('system', 0, 'Hydro', 'Hydro System');
// TODO discussion node?
},
// Add history column to ddoc,drdoc,psdoc
async function _1_2() {
const domains = await domain.getMulti().project({ _id: 1 }).toArray();
for (const d of domains) {
const bulk = document.coll.initializeUnorderedBulkOp();
await document.getMulti(d._id, document.TYPE_DISCUSSION).forEach((ddoc) => {
bulk.find({ _id: ddoc._id }).updateOne({ $set: { history: [] } });
});
await document.getMulti(d._id, document.TYPE_DISCUSSION_REPLY).forEach((drdoc) => {
bulk.find({ _id: drdoc._id }).updateOne({ $set: { history: [] } });
});
// TODO tail reply
await document.getMulti(d._id, document.TYPE_PROBLEM_SOLUTION).forEach((psdoc) => {
bulk.find({ _id: psdoc._id }).updateOne({ $set: { history: [] } });
});
if (bulk.length) await bulk.execute();
}
},
];
export = scripts;