Added basic version tracking to statistics document.
This commit is contained in:
parent
a01d94a57e
commit
8d7d08d5c0
1 changed files with 18 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ const {mongoose} = require('mongoose');
|
||||||
|
|
||||||
//Local Imports
|
//Local Imports
|
||||||
const config = require('./../../config.json');
|
const config = require('./../../config.json');
|
||||||
|
const package = require('../../package.json');
|
||||||
const tokeSchema = require('./tokebot/tokeSchema');
|
const tokeSchema = require('./tokebot/tokeSchema');
|
||||||
const loggerUtils = require('./../utils/loggerUtils');
|
const loggerUtils = require('./../utils/loggerUtils');
|
||||||
|
|
||||||
|
|
@ -46,6 +47,10 @@ const statSchema = new mongoose.Schema({
|
||||||
type: mongoose.SchemaTypes.Date,
|
type: mongoose.SchemaTypes.Date,
|
||||||
required: true,
|
required: true,
|
||||||
default: new Date()
|
default: new Date()
|
||||||
|
},
|
||||||
|
version:{
|
||||||
|
type: mongoose.SchemaTypes.String,
|
||||||
|
default: "<0.2.0"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -65,6 +70,14 @@ statSchema.statics.getStats = async function(){
|
||||||
var stats = await this.findOne({});
|
var stats = await this.findOne({});
|
||||||
|
|
||||||
if(stats){
|
if(stats){
|
||||||
|
//If the current listed version doesnt match current running version
|
||||||
|
if(stats.version != package.version){
|
||||||
|
//Update stat version
|
||||||
|
stats.version = package.version;
|
||||||
|
//Save stat document
|
||||||
|
await stats.save();
|
||||||
|
}
|
||||||
|
|
||||||
//If we found something then the statistics document exist and this is it,
|
//If we found something then the statistics document exist and this is it,
|
||||||
//So long as no one else has fucked with the database it should be the only one. (is this forshadowing for a future bug?)
|
//So long as no one else has fucked with the database it should be the only one. (is this forshadowing for a future bug?)
|
||||||
return stats;
|
return stats;
|
||||||
|
|
@ -74,6 +87,11 @@ statSchema.statics.getStats = async function(){
|
||||||
|
|
||||||
//create and save the statistics document
|
//create and save the statistics document
|
||||||
stats = await this.create({});
|
stats = await this.create({});
|
||||||
|
|
||||||
|
//Update stat version
|
||||||
|
stats.version = package.version;
|
||||||
|
|
||||||
|
//Save stat document
|
||||||
await stats.save();
|
await stats.save();
|
||||||
|
|
||||||
//live up to the name of the function
|
//live up to the name of the function
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue