Create DB form schema on start if config option is set

This commit is contained in:
Joe Dowd 2020-02-13 00:03:09 +00:00
parent 2cfe8964f3
commit 7acb19756b
2 changed files with 10 additions and 2 deletions

View file

@ -8,6 +8,9 @@
"behindProxy": true,
"db": "./databases/sponsorTimes.db",
"privateDB": "./databases/private.db",
"createDatabaseIfNotExist": true, //depends on mode='development' //This will run on startup every time - so ensure "create table if not exists" is used in the schema
"dbSchema": "./databases/_sponsorTimes.db.sql",
"privateDBSchema": "./databases/_private.db.sql",
"mode": "development",
"readOnly": false
}

View file

@ -29,6 +29,11 @@ var db = new Sqlite3(config.db, options);
//where the more sensitive data such as IP addresses are stored
var privateDB = new Sqlite3(config.privateDB, options);
if (config.createDatabaseIfNotExist && (config.mode === "development")) {
db.exec(fs.readFileSync(config.dbSchema).toString());
privateDB.exec(fs.readFileSync(config.privateDBSchema).toString());
}
// Create an HTTP service.
http.createServer(app).listen(config.port);