mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
migrate: add lock
This commit is contained in:
3 files changed
+19
-6
No files matched your search
@@ -520,6 +520,7 @@ ${nixConfBase}`);
|
|||||||
skip: () => migration !== 'hustoj',
|
skip: () => migration !== 'hustoj',
|
||||||
silent: true,
|
silent: true,
|
||||||
operations: [
|
operations: [
|
||||||
|
'pm2 restart hydrooj',
|
||||||
() => {
|
() => {
|
||||||
const dbInc = readFileSync('/home/judge/src/web/include/db_info.inc.php', 'utf-8');
|
const dbInc = readFileSync('/home/judge/src/web/include/db_info.inc.php', 'utf-8');
|
||||||
const l = dbInc.split('\n');
|
const l = dbInc.split('\n');
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import {
|
import {
|
||||||
Context, md5, Schema, sha1,
|
Context, md5, Schema, sha1,
|
||||||
|
SystemError,
|
||||||
|
SystemModel,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
|
|
||||||
const RE_MD5 = /^[\da-f]{32}$/;
|
const RE_MD5 = /^[\da-f]{32}$/;
|
||||||
|
|
||||||
|
function checkLock(innerCall) {
|
||||||
|
return async (args) => {
|
||||||
|
const cur = await SystemModel.get('migrate.lock');
|
||||||
|
if (cur) throw new SystemError(`migrate lock already exists: ${cur}, possible another migration is running`);
|
||||||
|
return innerCall(args);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function apply(ctx: Context) {
|
export function apply(ctx: Context) {
|
||||||
ctx.addScript(
|
ctx.addScript(
|
||||||
'migrateHustoj', 'migrate from hustoj',
|
'migrateHustoj', 'migrate from hustoj',
|
||||||
@@ -19,7 +29,7 @@ export function apply(ctx: Context) {
|
|||||||
dataDir: Schema.string().required(),
|
dataDir: Schema.string().required(),
|
||||||
uploadDir: Schema.string().default('/home/judge/src/web/upload/'),
|
uploadDir: Schema.string().default('/home/judge/src/web/upload/'),
|
||||||
}),
|
}),
|
||||||
(...args) => require('./scripts/hustoj').run(...args),
|
checkLock((...args) => require('./scripts/hustoj').run(...args)),
|
||||||
);
|
);
|
||||||
ctx.addScript(
|
ctx.addScript(
|
||||||
'migrateSyzoj', 'migrate from syzoj',
|
'migrateSyzoj', 'migrate from syzoj',
|
||||||
@@ -33,7 +43,7 @@ export function apply(ctx: Context) {
|
|||||||
dataDir: Schema.string().default('/opt/syzoj/web/uploads'),
|
dataDir: Schema.string().default('/opt/syzoj/web/uploads'),
|
||||||
randomMail: Schema.union(['never', 'needed', 'always']).default('never'),
|
randomMail: Schema.union(['never', 'needed', 'always']).default('never'),
|
||||||
}),
|
}),
|
||||||
(...args) => require('./scripts/syzoj').run(...args),
|
checkLock((...args) => require('./scripts/syzoj').run(...args)),
|
||||||
);
|
);
|
||||||
ctx.addScript(
|
ctx.addScript(
|
||||||
'migrateVijos', 'migrate from vijos',
|
'migrateVijos', 'migrate from vijos',
|
||||||
@@ -44,7 +54,7 @@ export function apply(ctx: Context) {
|
|||||||
username: Schema.string().required(),
|
username: Schema.string().required(),
|
||||||
password: Schema.string().required(),
|
password: Schema.string().required(),
|
||||||
}),
|
}),
|
||||||
(...args) => require('./scripts/vijos').run(...args),
|
checkLock((...args) => require('./scripts/vijos').run(...args)),
|
||||||
);
|
);
|
||||||
ctx.addScript(
|
ctx.addScript(
|
||||||
'migrateUniversaloj', 'migrate from universaloj',
|
'migrateUniversaloj', 'migrate from universaloj',
|
||||||
@@ -57,7 +67,7 @@ export function apply(ctx: Context) {
|
|||||||
domainId: Schema.string().default('system'),
|
domainId: Schema.string().default('system'),
|
||||||
dataDir: Schema.string().required(),
|
dataDir: Schema.string().required(),
|
||||||
}),
|
}),
|
||||||
(...args) => require('./scripts/universaloj').run(...args),
|
checkLock((...args) => require('./scripts/universaloj').run(...args)),
|
||||||
);
|
);
|
||||||
ctx.addScript(
|
ctx.addScript(
|
||||||
'migratePoj', 'migrate from poj',
|
'migratePoj', 'migrate from poj',
|
||||||
@@ -72,14 +82,14 @@ export function apply(ctx: Context) {
|
|||||||
dataDir: Schema.string().required(),
|
dataDir: Schema.string().required(),
|
||||||
imageDir: Schema.string().required(),
|
imageDir: Schema.string().required(),
|
||||||
}),
|
}),
|
||||||
(...args) => require('./scripts/poj').run(...args),
|
checkLock((...args) => require('./scripts/poj').run(...args)),
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.provideModule('hash', 'hust', ($password, $saved) => {
|
ctx.provideModule('hash', 'hust', ($password, $saved) => {
|
||||||
$password = md5($password);
|
$password = md5($password);
|
||||||
if (RE_MD5.test($saved)) return $password === $saved;
|
if (RE_MD5.test($saved)) return $password === $saved;
|
||||||
const $svd = Buffer.from($saved, 'base64').toString('hex');
|
const $svd = Buffer.from($saved, 'base64').toString('hex');
|
||||||
const $salt = Buffer.from($svd.substr(40), 'hex').toString();
|
const $salt = Buffer.from($svd.substring(40), 'hex').toString();
|
||||||
const $hash = Buffer.concat([
|
const $hash = Buffer.concat([
|
||||||
Buffer.from(sha1($password + $salt), 'hex'),
|
Buffer.from(sha1($password + $salt), 'hex'),
|
||||||
Buffer.from($salt),
|
Buffer.from($salt),
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ export async function run({
|
|||||||
const target = await DomainModel.get(domainId);
|
const target = await DomainModel.get(domainId);
|
||||||
if (!target) throw new NotFoundError(domainId);
|
if (!target) throw new NotFoundError(domainId);
|
||||||
report({ message: 'Connected to database' });
|
report({ message: 'Connected to database' });
|
||||||
|
await SystemModel.set('migrate.lock', 'hustoj');
|
||||||
/*
|
/*
|
||||||
user_id varchar 20 N 用户id(主键)
|
user_id varchar 20 N 用户id(主键)
|
||||||
email varchar 100 Y 用户E-mail
|
email varchar 100 Y 用户E-mail
|
||||||
@@ -349,5 +350,6 @@ hydrooj install https://hydro.ac/hydroac-client.zip
|
|||||||
}
|
}
|
||||||
await ProblemModel.addTestdata(domainId, pdoc.docId, 'config.yaml', Buffer.from(pdoc.config as string));
|
await ProblemModel.addTestdata(domainId, pdoc.docId, 'config.yaml', Buffer.from(pdoc.config as string));
|
||||||
}
|
}
|
||||||
|
await SystemModel.set('migrate.lock', 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user