Added schema upgrade system and started on new vote type

This commit is contained in:
Ajay Ramachandran
2020-04-27 23:01:51 -04:00
parent 74169e6caf
commit d767f2ff6b
9 changed files with 216 additions and 172 deletions

View File

@@ -15,6 +15,13 @@ if (config.createDatabaseIfNotExist && !config.readOnly) {
if (fs.existsSync(config.privateDBSchema)) privateDB.exec(fs.readFileSync(config.privateDBSchema).toString());
}
// Upgrade database if required
let versionCode = db.prepare("SELECT code FROM version").get() || 0;
let path = config.schemaFolder + "/_upgrade_" + versionCode + ".sql";
if (fs.existsSync(path)) {
db.exec(fs.readFileSync(path).toString());
}
// Enable WAL mode checkpoint number
if (!config.readOnly && config.mode === "production") {
db.exec("PRAGMA journal_mode=WAL;");