Merge pull request #201 from Cryptkeeper/daily-db
5.5.8 release preview
This commit is contained in:
commit
bfa3ae5150
@ -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.
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "minetrack",
|
||||
"version": "5.5.7",
|
||||
"version": "5.5.8",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user