2020-11-01 20:47:47 +00:00
|
|
|
import * as queries from "./queries";
|
2020-11-29 20:30:27 +00:00
|
|
|
import { log, LogLevel } from "./logging"
|
|
|
|
import express from "express";
|
2020-11-01 20:47:47 +00:00
|
|
|
import pg from "pg";
|
|
|
|
import db from "./db";
|
|
|
|
|
|
|
|
var versionMajor = 0;
|
2021-02-26 02:56:14 +00:00
|
|
|
var versionMinor = 6;
|
|
|
|
var versionPatch = 0;
|
2020-11-01 20:47:47 +00:00
|
|
|
|
|
|
|
export function getVersion() {
|
|
|
|
return `${versionMajor}.${versionMinor}.${versionPatch}`
|
|
|
|
}
|
|
|
|
|
2020-11-29 20:30:27 +00:00
|
|
|
export async function checkVersionMiddleware(_req: express.Request, _res: express.Response, next: express.NextFunction) {
|
|
|
|
try {
|
|
|
|
await checkVersion();
|
|
|
|
} catch (e) {
|
|
|
|
log(LogLevel.ERROR,e)
|
|
|
|
// Terminate the nodejs process with error. If restarted, the app will
|
|
|
|
// never start listening for new requests so this will not result in a
|
|
|
|
// restart loop.
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
2020-11-01 20:47:47 +00:00
|
|
|
export async function checkVersion() {
|
|
|
|
var dbver = await db.query(queries.getDbVersion).then((result: pg.QueryResult) => result.rows[0]['get_version']);
|
|
|
|
if (dbver != `${versionMajor}.${versionMinor}`) {
|
|
|
|
throw new Error("Version mismatch!\nApplication version: " + getVersion() + "\nDatabase version: " + dbver)
|
|
|
|
}
|
|
|
|
}
|