diff --git a/config.json.example b/config.json.example index d771410..b90e11e 100644 --- a/config.json.example +++ b/config.json.example @@ -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 -} \ No newline at end of file +} diff --git a/index.js b/index.js index e0c993f..73727ba 100644 --- a/index.js +++ b/index.js @@ -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); @@ -1049,4 +1054,4 @@ function getFormattedTime(seconds) { let formatted = minutes+ ":" + secondsDisplay; return formatted; -} \ No newline at end of file +}