Added basic version tracking to statistics document.

This commit is contained in:
rainbow napkin 2026-05-29 06:35:22 -04:00
parent a01d94a57e
commit 8d7d08d5c0

View file

@ -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