From 7e5c0176541c1839a7a54c2850cab30fea155887 Mon Sep 17 00:00:00 2001 From: Nick Krecklow Date: Sat, 1 Aug 2020 14:46:04 -0500 Subject: [PATCH 1/2] add: named daily database copies for automating exports --- lib/database.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/database.js b/lib/database.js index ee7481a9..c0bfe7c5 100644 --- a/lib/database.js +++ b/lib/database.js @@ -1,5 +1,6 @@ const sqlite = require('sqlite3') +const config = require('../config') const { TimeTracker } = require('./time') class Database { @@ -8,6 +9,32 @@ class Database { this._sql = new sqlite.Database('database.sql') } + getDailyDatabase () { + if (!config.createDailyDatabaseCopy) { + return + } + + const date = new Date() + const fileName = `database_copy_${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}.sql` + + if (fileName !== this._currentDatabaseCopyFileName) { + if (this._currentDatabaseCopyInstance) { + this._currentDatabaseCopyInstance.close() + } + + this._currentDatabaseCopyInstance = new sqlite.Database(fileName) + this._currentDatabaseCopyFileName = fileName + + // Ensure the initial tables are created + // This does not created indexes since it is only inserted to + this._currentDatabaseCopyInstance.serialize(() => { + this._currentDatabaseCopyInstance.run('CREATE TABLE IF NOT EXISTS pings (timestamp BIGINT NOT NULL, ip TINYTEXT, playerCount MEDIUMINT)') + }) + } + + return this._currentDatabaseCopyInstance + } + ensureIndexes () { this._sql.serialize(() => { this._sql.run('CREATE TABLE IF NOT EXISTS pings (timestamp BIGINT NOT NULL, ip TINYTEXT, playerCount MEDIUMINT)') @@ -122,7 +149,18 @@ class Database { } insertPing (ip, timestamp, unsafePlayerCount) { - const statement = this._sql.prepare('INSERT INTO pings (timestamp, ip, playerCount) VALUES (?, ?, ?)') + this._insertPingTo(ip, timestamp, unsafePlayerCount, this._sql) + + // Push a copy of the data into the database copy, if any + // This creates an "insert only" copy of the database for archiving + const dailyDatabase = this.getDailyDatabase() + if (dailyDatabase) { + this._insertPingTo(ip, timestamp, unsafePlayerCount, dailyDatabase) + } + } + + _insertPingTo (ip, timestamp, unsafePlayerCount, db) { + const statement = db.prepare('INSERT INTO pings (timestamp, ip, playerCount) VALUES (?, ?, ?)') statement.run(timestamp, ip, unsafePlayerCount) statement.finalize() } From 783b49ee15a18c0251efe562afeee4f124fc34bb Mon Sep 17 00:00:00 2001 From: Nick Krecklow Date: Sat, 1 Aug 2020 14:54:23 -0500 Subject: [PATCH 2/2] 5.5.8 --- docs/CHANGELOG.md | 4 ++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e4ae5702..a7dbc405 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,7 @@ +**5.5.8** *(August 1 2020)* +- Adds daily database copies. This is mostly for use by Minetrack Data for automated exports. By setting `createDailyDatabaseCopy: true` in `config.json`, Minetrack will lazily create a copy of `database.sql` for each day, automatically rolling over to a new file each day. The database file is named in the format of `database_copy_(day)-(month)-(year).sql`. Daily database copies do not contain indexes or previous records. Pings are inserted into the daily database copy as they occur, Minetrack will not retroactively insert previous pings from `database.sql`. +- Bump lodash from 4.17.15 to 4.17.19 + **5.5.7** *(July 7 2020)* - Fixes an issue in which the light theme CSS may not be applied by default. diff --git a/package-lock.json b/package-lock.json index dd0f6391..4cf6e3c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "minetrack", - "version": "5.5.7", + "version": "5.5.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 91c3e296..a32ef3d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minetrack", - "version": "5.5.7", + "version": "5.5.8", "description": "A Minecraft server tracker that lets you focus on the basics.", "main": "main.js", "dependencies": {