mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add history for psdoc,ddoc,drdoc
This commit is contained in:
1 parent
c49970f4be
commit
b8c316c44b
12 files changed
+70
-32
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user