From a6297bfe9bee2c1df4102b3cdb98e4f07bf4faa7 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 19 Mar 2021 12:45:04 +0800 Subject: [PATCH] core: better upgrade mode --- package.json | 10 +++++----- packages/hydrojudge/package.json | 2 +- packages/hydrooj/package.json | 6 +++--- packages/hydrooj/src/upgrade.ts | 28 ++++++++++++++++------------ packages/migrate-vijos/package.json | 2 +- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 0e2bdc1ce..9efad42e6 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,10 @@ "@shelf/jest-mongodb": "^1.2.3", "@types/cross-spawn": "^6.0.2", "@types/jest": "^26.0.20", - "@types/node": "^14.14.34", + "@types/node": "^14.14.35", "@types/semver": "^7.3.4", - "@typescript-eslint/eslint-plugin": "^4.17.0", - "@typescript-eslint/parser": "^4.17.0", + "@typescript-eslint/eslint-plugin": "^4.18.0", + "@typescript-eslint/parser": "^4.18.0", "cross-spawn": "^7.0.3", "eslint": "^7.22.0", "eslint-config-airbnb-typescript": "^12.0.0", @@ -33,9 +33,9 @@ "globby": "^11.0.2", "jest": "^26.6.3", "latest-version": "^5.1.0", - "ora": "^5.3.0", + "ora": "^5.4.0", "semver": "^7.3.4", - "ts-jest": "^26.5.3", + "ts-jest": "^26.5.4", "typescript": "4.2.3" }, "dependencies": { diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index d5521f8fb..702547908 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -17,7 +17,7 @@ "lodash": "^4.17.21", "p-queue": "^6.6.1", "shell-quote": "^1.7.2", - "systeminformation": "5.6.4", + "systeminformation": "5.6.7", "ws": "^7.4.4", "yargs": "^16.2.0" }, diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index bb01408a8..1d4eb669f 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.20.23", + "version": "2.20.24", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", @@ -27,14 +27,14 @@ "lru-cache": "^6.0.0", "minio": "7.0.17", "moment-timezone": "^0.5.32", - "mongodb": "^3.6.4", + "mongodb": "^3.6.5", "nodemailer": "^6.5.0", "p-queue": "^6.6.2", "reflect-metadata": "^0.1.13", "serialize-javascript": "^5.0.1", "sockjs": "^0.3.20", "superagent": "^6.1.0", - "systeminformation": "5.6.4", + "systeminformation": "5.6.7", "wtfnode": "^0.8.4", "yargs": "^16.2.0" }, diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index 0e45baa3f..6bdf99e52 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -49,15 +49,19 @@ async function iterateAllProblem( } const scripts: UpgradeScript[] = [ - // Init + // Mark as used async function _0_1() { + return true; + }, + // Init + async function _1_2() { const ddoc = await domain.get('system'); if (!ddoc) await domain.add('system', 1, 'Hydro', 'Hydro System'); // TODO discussion node? return true; }, // Add history column to ddoc,drdoc,psdoc - async function _1_2() { + async function _2_3() { const _FRESH_INSTALL_IGNORE = 1; await iterateAllDomain(async (d) => { const bulk = document.coll.initializeUnorderedBulkOp(); @@ -75,12 +79,12 @@ const scripts: UpgradeScript[] = [ }); return true; }, - async function _2_3() { + async function _3_4() { const _FRESH_INSTALL_IGNORE = 1; await db.collection('document').updateMany({ pid: /^\d+$/i }, { $unset: { pid: '' } }); return true; }, - async function _3_4() { + async function _4_5() { const _FRESH_INSTALL_IGNORE = 1; if (storage.error) { logger.error('Cannot upgrade. Please change storage config.'); @@ -131,7 +135,7 @@ const scripts: UpgradeScript[] = [ logger.success('Files copied successfully. You can now remove collection `file` `fs.files` `fs.chunks` in the database.'); return true; }, - async function _4_5() { + async function _5_6() { const _FRESH_INSTALL_IGNORE = 1; await iterateAllDomain(async (d) => { const bulk = document.coll.initializeUnorderedBulkOp(); @@ -144,16 +148,16 @@ const scripts: UpgradeScript[] = [ }); return true; }, - async function _5_6() { + async function _6_7() { // Issue #58 const _FRESH_INSTALL_IGNORE = 1; await domain.edit('system', { owner: 1 }); return true; }, - async function _6_7() { + async function _7_8() { return true; // invalid }, - async function _7_8() { + async function _8_9() { const _FRESH_INSTALL_IGNORE = 1; await iterateAllProblem(['docId', 'domainId', 'config'], async (pdoc) => { logger.info('%s/%s', pdoc.domainId, pdoc.docId); @@ -169,7 +173,7 @@ const scripts: UpgradeScript[] = [ }); return true; }, - async function _8_9() { + async function _9_10() { const _FRESH_INSTALL_IGNORE = 1; await iterateAllProblem([], async (pdoc) => { logger.info('%s/%s', pdoc.domainId, pdoc.docId); @@ -188,7 +192,7 @@ const scripts: UpgradeScript[] = [ return true; }, // Move category to tag - async function _9_10() { + async function _10_11() { const _FRESH_INSTALL_IGNORE = 1; await iterateAllProblem(['tag', 'category'], async (pdoc) => { await document.coll.updateOne( @@ -202,13 +206,13 @@ const scripts: UpgradeScript[] = [ return true; }, // Set null tag to [] - async function _10_11() { + async function _11_12() { const _FRESH_INSTALL_IGNORE = 1; await db.collection('document').updateMany({ docType: 10, tag: null }, { $set: { tag: [] } }); return true; }, // Update problem difficulty - async function _11_12() { + async function _12_13() { const _FRESH_INSTALL_IGNORE = 1; await iterateAllProblem(['nSubmit', 'nAccept'], async (pdoc) => { const difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept); diff --git a/packages/migrate-vijos/package.json b/packages/migrate-vijos/package.json index 77961a2b6..4086e4dd7 100644 --- a/packages/migrate-vijos/package.json +++ b/packages/migrate-vijos/package.json @@ -16,6 +16,6 @@ "hydrooj": "^2.17.22" }, "dependencies": { - "mongodb": "^3.6.4" + "mongodb": "^3.6.5" } } \ No newline at end of file