mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:47:08 +00:00
Update version checking mechanism.
Checks both database schema and API versions.
This commit is contained in:
@@ -5,7 +5,7 @@ async function main () {
|
||||
const version = require('./lib/version');
|
||||
console.log("Running version", await version.describe());
|
||||
version.compatible()
|
||||
.then( () => {
|
||||
.then( (versions) => {
|
||||
const api = require('./api');
|
||||
const ws = require('./ws');
|
||||
|
||||
@@ -17,10 +17,12 @@ async function main () {
|
||||
const eventManagerPath = [__dirname, "events"].join("/");
|
||||
const eventManager = fork(eventManagerPath, /*{ stdio: 'ignore' }*/);
|
||||
|
||||
console.info("Versions", versions);
|
||||
|
||||
process.on('exit', () => eventManager.kill());
|
||||
})
|
||||
.catch( ({current, wanted}) => {
|
||||
console.error(`Fatal error: incompatible database schema version ${current} (wanted: ${wanted})`);
|
||||
.catch( ({current, wanted, component}) => {
|
||||
console.error(`Fatal error: incompatible ${component} version ${current} (wanted: ${wanted})`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,14 @@ const semver = require("semver");
|
||||
const { exec } = require("child_process");
|
||||
const pkg = require("../package.json");
|
||||
|
||||
|
||||
function compatible () {
|
||||
return Promise.all([
|
||||
compatible_schema(),
|
||||
compatible_api()
|
||||
]);
|
||||
}
|
||||
|
||||
/** Report whether the database schema version is
|
||||
* compatible with the version required by this server.
|
||||
*
|
||||
@@ -14,15 +22,30 @@ const pkg = require("../package.json");
|
||||
* @returns true if the versions are compatible,
|
||||
* false otherwise.
|
||||
*/
|
||||
function compatible () {
|
||||
function compatible_schema () {
|
||||
const { info } = require('./db');
|
||||
return new Promise ( async (resolve, reject) => {
|
||||
const current = await info.get(null, "version/db_schema");
|
||||
const wanted = pkg.config.db_schema;
|
||||
const component = "schema";
|
||||
if (semver.satisfies(current, wanted)) {
|
||||
resolve({current, wanted});
|
||||
resolve({current, wanted, component});
|
||||
} else {
|
||||
reject({current, wanted});
|
||||
reject({current, wanted, component});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function compatible_api () {
|
||||
const api = require('../api');
|
||||
return new Promise ( async (resolve, reject) => {
|
||||
const current = api.locals.version;
|
||||
const wanted = pkg.config.api;
|
||||
const component = "api";
|
||||
if (semver.satisfies(current, wanted)) {
|
||||
resolve({current, wanted, component});
|
||||
} else {
|
||||
reject({current, wanted, component});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user