mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
workspace: upgrade to cordis@4.0.0-beta.1, fix #975
This commit is contained in:
34 files changed
+87
-88
No files matched your search
@@ -1,7 +1,7 @@
|
||||
// TODO check more
|
||||
|
||||
import os from 'os';
|
||||
import { DisposableList } from '@cordisjs/core';
|
||||
import { DisposableList } from 'cordis';
|
||||
import { Context, Service } from '../context';
|
||||
import * as system from '../model/system';
|
||||
import db from './db';
|
||||
|
||||
@@ -62,7 +62,7 @@ export class MongoService extends Service {
|
||||
yield () => { this.client.close(); };
|
||||
this.db = this.client.db(url.database || 'hydro');
|
||||
await bus.parallel('database/connect', this.db);
|
||||
yield this.ctx.setInterval(() => this.fixExpireAfter(), Time.hour);
|
||||
yield this.ctx.interval(() => this.fixExpireAfter(), Time.hour);
|
||||
}
|
||||
|
||||
public collection<K extends keyof Collections>(c: K) {
|
||||
|
||||
@@ -209,7 +209,7 @@ export default class HMR extends Service {
|
||||
|
||||
const reload = async (plugin: any, runtime?: Plugin.Runtime) => {
|
||||
if (!runtime) return;
|
||||
for (const oldFiber of runtime.scopes) {
|
||||
for (const oldFiber of runtime.fibers) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await oldFiber.parent.plugin(plugin, oldFiber.config);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import cac from 'cac';
|
||||
import { Logger } from '@hydrooj/utils';
|
||||
import { Context, Service } from '../context';
|
||||
import * as system from '../model/system';
|
||||
|
||||
const argv = cac().parse();
|
||||
|
||||
export type MigrationScript = null | ((ctx: Context) => Promise<boolean | void>);
|
||||
const logger = new Logger('migration');
|
||||
|
||||
@@ -43,6 +46,18 @@ export default class MigrationService extends Service {
|
||||
await system.set(name, expected);
|
||||
continue;
|
||||
}
|
||||
let upgraded = false;
|
||||
if (dbVer > expected) {
|
||||
logger.warn('Current database version for [%s] is %d, expected %d.', channel, dbVer, expected);
|
||||
logger.warn('You are likely trying to apply a downgrade.');
|
||||
logger.warn('This version of Hydro is not compatible with newer data version.');
|
||||
if (!argv.options.ignoreVersion) {
|
||||
logger.warn('To prevent data corruption, the startup has been aborted.');
|
||||
logger.warn('If you want to continue, use --ignore-version on startup.');
|
||||
logger.warn('Do it at your own risk.');
|
||||
await new Promise(() => { });
|
||||
}
|
||||
}
|
||||
while (dbVer < expected) {
|
||||
const func = scripts[dbVer];
|
||||
if (typeof func !== 'function') {
|
||||
@@ -62,8 +77,9 @@ export default class MigrationService extends Service {
|
||||
}
|
||||
dbVer++;
|
||||
await system.set(name, dbVer);
|
||||
upgraded = true;
|
||||
}
|
||||
logger.success('Database upgraded [%s]: current version %d', channel, dbVer);
|
||||
if (upgraded) logger.success('Database upgraded [%s]: current version %d', channel, dbVer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,5 +107,5 @@ export async function apply(ctx: Context) {
|
||||
{ upsert: true },
|
||||
);
|
||||
feedback();
|
||||
return ctx.setInterval(update, 1800 * 1000); // eslint-disable-line
|
||||
return ctx.interval(update, 1800 * 1000); // eslint-disable-line
|
||||
}
|
||||
@@ -425,7 +425,7 @@ export async function apply(ctx: Context, config: ReturnType<typeof FileSetting>
|
||||
return await next();
|
||||
});
|
||||
});
|
||||
ctx.set('storage', service);
|
||||
ctx.provide('storage', service);
|
||||
}
|
||||
|
||||
declare module '../context' {
|
||||
|
||||
Reference in new issue
Block a user