You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
4 years ago
|
/* 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;
|