diff --git a/src/schemas/statSchema.js b/src/schemas/statSchema.js index 8c680c3..fd406d5 100644 --- a/src/schemas/statSchema.js +++ b/src/schemas/statSchema.js @@ -19,6 +19,7 @@ const {mongoose} = require('mongoose'); //Local Imports const config = require('./../../config.json'); +const package = require('../../package.json'); const tokeSchema = require('./tokebot/tokeSchema'); const loggerUtils = require('./../utils/loggerUtils'); @@ -46,6 +47,10 @@ const statSchema = new mongoose.Schema({ type: mongoose.SchemaTypes.Date, required: true, 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({}); 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, //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; @@ -74,6 +87,11 @@ statSchema.statics.getStats = async function(){ //create and save the statistics document stats = await this.create({}); + + //Update stat version + stats.version = package.version; + + //Save stat document await stats.save(); //live up to the name of the function