import * as queries from "./queries"; import { log, LogLevel } from "./logging" import express from "express"; import pg from "pg"; import db from "./db"; var versionMajor = 0; var versionMinor = 5; var versionPatch = 1; export function getVersion() { return `${versionMajor}.${versionMinor}.${versionPatch}` } 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(); } 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) } }