parent
8e47cd9ea9
commit
767cfbf488
|
@ -0,0 +1,11 @@
|
|||
CREATE TABLE version (
|
||||
major INT NOT NULL,
|
||||
minor INT NOT NULL,
|
||||
PRIMARY KEY (major,minor)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_version() RETURNS VARCHAR
|
||||
AS $$SELECT major || '.' || minor FROM version $$
|
||||
LANGUAGE SQL;
|
||||
|
||||
INSERT INTO version (major,minor) VALUES (0,1);
|
|
@ -11,6 +11,7 @@ import pgSessionStore from "connect-pg-simple";
|
|||
import fetch, { Response as FetchResponse } from "node-fetch";
|
||||
import db from "./db";
|
||||
import errorHandler from "./errors";
|
||||
import * as version from "./version";
|
||||
|
||||
|
||||
console.log("Starting at " + new Date().toISOString());
|
||||
|
@ -345,6 +346,7 @@ async function processBannedUsers() {
|
|||
|
||||
setTimeout(processBannedUsers,600000+Math.floor(Math.random()*600000))
|
||||
|
||||
app.listen(config.port, () => {
|
||||
// Check version then listen
|
||||
version.checkVersion().then(_ => app.listen(config.port, () => {
|
||||
console.log(`Listening on port ${config.port}`);
|
||||
});
|
||||
}));
|
||||
|
|
|
@ -96,3 +96,8 @@ export const getValidStates = {
|
|||
name: "getValidStates",
|
||||
text: "SELECT * FROM states"
|
||||
}
|
||||
|
||||
export const getDbVersion = {
|
||||
name: "getDbVersion",
|
||||
text: "SELECT get_version()"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import * as queries from "./queries";
|
||||
import pg from "pg";
|
||||
import db from "./db";
|
||||
|
||||
var versionMajor = 0;
|
||||
var versionMinor = 1;
|
||||
var versionPatch = 0;
|
||||
|
||||
export function getVersion() {
|
||||
return `${versionMajor}.${versionMinor}.${versionPatch}`
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue