Simplify versions handling

This commit is contained in:
D. Berge
2023-11-02 23:47:13 +01:00
parent 3709070985
commit 2e21526fca
4 changed files with 11 additions and 30 deletions

View File

@@ -10,7 +10,6 @@ const mw = require('./middleware');
const { ERROR, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
const verbose = process.env.NODE_ENV != 'test';
const app = express();
app.locals.version = "0.4.0"; // API version
app.map = function(a, route){
route = route || '';

View File

@@ -3,15 +3,13 @@ const { exec } = require("child_process");
const { readFileSync } = require('fs');
const { pool } = require('./db/connection');
const { info } = require('./db');
const api = require('../api');
const pkg = require("../package.json");
const { ALERT, ERROR, WARNING, NOTICE, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
function compatible () {
return Promise.all([
compatible_schema(),
compatible_api()
compatible_schema()
]);
}
@@ -30,7 +28,7 @@ function compatible () {
function compatible_schema () {
return new Promise ( async (resolve, reject) => {
const current = await schema_version();
const wanted = pkg.config.db_schema;
const wanted = pkg.config.wanted.db_schema;
const component = "schema";
if (semver.satisfies(current, wanted)) {
resolve({current, wanted, component});
@@ -40,19 +38,6 @@ function compatible_schema () {
});
}
function compatible_api () {
return new Promise ( async (resolve, reject) => {
const current = api_version();
const wanted = pkg.config.api;
const component = "api";
if (semver.satisfies(current, wanted)) {
resolve({current, wanted, component});
} else {
reject({current, wanted, component});
}
});
}
async function db_version () {
const client = await pool.connect();
let res;
@@ -89,11 +74,6 @@ async function schema_version () {
return await info.get(null, "version/db_schema");
}
function api_version () {
return api.locals.version;
}
/** Return software name.
*
*/
@@ -131,20 +111,18 @@ async function version () {
const name = app_name();
const server = pkg.version;
const tag = await describe();
const api = await api_version();
const schema = await schema_version();
const db = await db_version();
const os = await os_version();
const compatibility = [
await compatible_schema(),
await compatible_api()
await compatible_schema()
]
return {
name,
server,
tag,
api,
...pkg?.config?.versions,
schema,
db,
os,

View File

@@ -12,8 +12,12 @@
"license": "UNLICENSED",
"private": true,
"config": {
"db_schema": "^0.4.5",
"api": "^0.4.0"
"versions": {
"api": "0.4.0"
},
"wanted": {
"db_schema": "^0.4.5"
}
},
"engines": {
"node": ">=18.0.0"

View File

@@ -1091,7 +1091,7 @@ components:
component:
description: The component being checked.
type: string
enum: [ "api", "schema" ]
enum: [ "schema" ]
current:
description: Current version number for this component.
type: string