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