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
+68
-30
No files matched your search
@@ -11,7 +11,7 @@ message.markAsRead
|
|||||||
解离mail模块
|
解离mail模块
|
||||||
存储系统抽象化
|
存储系统抽象化
|
||||||
extend problem settings
|
extend problem settings
|
||||||
+oplog
|
|
||||||
将系统设置存于本地而非数据库
|
将系统设置存于本地而非数据库
|
||||||
添加nav排序功能
|
添加nav排序功能
|
||||||
自动拓扑组件加载顺序?
|
自动拓扑组件加载顺序?
|
||||||
|
add declarations to psdoc
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.13.24",
|
"version": "2.13.25",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ export const builtinHandler = [
|
|||||||
|
|
||||||
export const builtinScript = [
|
export const builtinScript = [
|
||||||
'rating', 'difficulty', 'problemStat', 'blacklist', 'deleteUser',
|
'rating', 'difficulty', 'problemStat', 'blacklist', 'deleteUser',
|
||||||
'upgrade0_1',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function getFiles(folder: string, base = ''): string[] {
|
function getFiles(folder: string, base = ''): string[] {
|
||||||
|
|||||||
@@ -58,10 +58,14 @@ export async function load(call: Entry) {
|
|||||||
require('../service/monitor');
|
require('../service/monitor');
|
||||||
for (const i of builtinModel) require(`../model/${i}`);
|
for (const i of builtinModel) require(`../model/${i}`);
|
||||||
const modelSystem = require('../model/system');
|
const modelSystem = require('../model/system');
|
||||||
const dbVer = await modelSystem.get('db.ver');
|
const scripts = require('../upgrade');
|
||||||
if (dbVer !== 1) {
|
let dbVer = (await modelSystem.get('db.ver')) || 0;
|
||||||
const ins = require('../script/upgrade0_1');
|
const expected = scripts.length;
|
||||||
await ins.run({ username: 'Root', password: 'rootroot' });
|
while (dbVer < expected) {
|
||||||
|
logger.info('Upgrading database: from %d to %d', dbVer, expected);
|
||||||
|
await scripts[dbVer]();
|
||||||
|
dbVer++;
|
||||||
|
await modelSystem.set('db.ver', dbVer);
|
||||||
}
|
}
|
||||||
bus.serial('app/started');
|
bus.serial('app/started');
|
||||||
return await modelSystem.get('server.worker');
|
return await modelSystem.get('server.worker');
|
||||||
|
|||||||
@@ -330,6 +330,11 @@ export interface Bdoc {
|
|||||||
expireAt: Date,
|
expireAt: Date,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface HistoryDoc {
|
||||||
|
content: string,
|
||||||
|
time: Date,
|
||||||
|
}
|
||||||
|
|
||||||
// Discussion
|
// Discussion
|
||||||
export interface Ddoc extends Document {
|
export interface Ddoc extends Document {
|
||||||
docType: document['TYPE_DISCUSSION'],
|
docType: document['TYPE_DISCUSSION'],
|
||||||
@@ -344,6 +349,7 @@ export interface Ddoc extends Document {
|
|||||||
updateAt: Date,
|
updateAt: Date,
|
||||||
nReply: number,
|
nReply: number,
|
||||||
views: number,
|
views: number,
|
||||||
|
history: HistoryDoc[],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discussion reply
|
// Discussion reply
|
||||||
@@ -355,6 +361,7 @@ export interface Drdoc extends Document {
|
|||||||
ip: string,
|
ip: string,
|
||||||
content: string,
|
content: string,
|
||||||
reply: Drrdoc[],
|
reply: Drrdoc[],
|
||||||
|
history: HistoryDoc[],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discussion Tail Reply
|
// Discussion Tail Reply
|
||||||
@@ -363,6 +370,7 @@ export interface Drrdoc {
|
|||||||
owner: number,
|
owner: number,
|
||||||
content: string,
|
content: string,
|
||||||
ip: string,
|
ip: string,
|
||||||
|
history: HistoryDoc[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TokenDoc {
|
export interface TokenDoc {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Dictionary } from 'lodash';
|
import { Dictionary } from 'lodash';
|
||||||
|
import { FilterQuery } from 'mongodb';
|
||||||
import { BUILTIN_ROLES, PRIV } from './builtin';
|
import { BUILTIN_ROLES, PRIV } from './builtin';
|
||||||
import { DomainDoc } from '../interface';
|
import { DomainDoc } from '../interface';
|
||||||
import * as db from '../service/db';
|
import * as db from '../service/db';
|
||||||
@@ -46,7 +47,7 @@ export function get(domainId: string): Promise<DomainDoc | null> {
|
|||||||
return coll.findOne({ _id: domainId });
|
return coll.findOne({ _id: domainId });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMulti(query: any = {}) {
|
export function getMulti(query: FilterQuery<DomainDoc> = {}) {
|
||||||
return coll.find(query);
|
return coll.find(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,11 +121,8 @@ export async function getList(
|
|||||||
if (pdocs.length !== pids.length) {
|
if (pdocs.length !== pids.length) {
|
||||||
for (const pid of pids) {
|
for (const pid of pids) {
|
||||||
if (!(r[pid] || l[pid])) {
|
if (!(r[pid] || l[pid])) {
|
||||||
if (doThrow) {
|
if (doThrow) throw new ProblemNotFoundError(domainId, pid);
|
||||||
throw new ProblemNotFoundError(domainId, pid);
|
else r[pid] = pdocHidden;
|
||||||
} else {
|
|
||||||
r[pid] = pdocHidden;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import * as domain from '../model/domain';
|
|
||||||
|
|
||||||
export const description = 'Upgrade database from 0 to 1';
|
|
||||||
|
|
||||||
export async function run() {
|
|
||||||
const ddoc = await domain.get('system');
|
|
||||||
if (!ddoc) await domain.add('system', 0, 'Hydro', 'Hydro System');
|
|
||||||
// TODO discussion node?
|
|
||||||
}
|
|
||||||
|
|
||||||
export const validate = {};
|
|
||||||
|
|
||||||
global.Hydro.script.upgrade0_1 = { run, description, validate };
|
|
||||||
@@ -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;
|
||||||
@@ -6,8 +6,15 @@ export async function connect() {
|
|||||||
const db = require('hydrooj/src/service/db');
|
const db = require('hydrooj/src/service/db');
|
||||||
db.bus.once('connect', resolve);
|
db.bus.once('connect', resolve);
|
||||||
});
|
});
|
||||||
const script = require('../src/script/upgrade0_1');
|
const modelSystem = require('hydrooj/src/model/system');
|
||||||
await script.run();
|
const scripts = require('hydrooj/src/upgrade');
|
||||||
|
let dbVer = (await modelSystem.get('db.ver')) || 0;
|
||||||
|
const expected = scripts.length;
|
||||||
|
while (dbVer < expected) {
|
||||||
|
await scripts[dbVer]();
|
||||||
|
dbVer++;
|
||||||
|
await modelSystem.set('db.ver', dbVer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dispose() {
|
export async function dispose() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/migrate-vijos",
|
"name": "@hydrooj/migrate-vijos",
|
||||||
"version": "1.3.8",
|
"version": "1.3.9",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <masnn0@outlook.com>",
|
"author": "undefined <masnn0@outlook.com>",
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"@types/mongodb": "^3.5.27"
|
"@types/mongodb": "^3.5.27"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"hydrooj": "^2.13.5"
|
"hydrooj": "^2.13.25"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-yaml": "^3.14.0",
|
"js-yaml": "^3.14.0",
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ const tasks = {
|
|||||||
content: r.content,
|
content: r.content,
|
||||||
owner: r.owner_uid,
|
owner: r.owner_uid,
|
||||||
ip: r.ip,
|
ip: r.ip,
|
||||||
|
history: [],
|
||||||
};
|
};
|
||||||
res.push(drrdoc);
|
res.push(drrdoc);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user