this.database.get("SELECT value FROM options WHERE name = 'schema_version'",(err,row)=>{
if(err){
returnlog.error(`Failed to retrieve schema version: ${err}`);
}
// New table
if(row===undefined){
this.database.serialize(()=>this.database.run("INSERT INTO options (name, value) VALUES ('schema_version', ?)",currentSchemaVersion));
return;
}
conststoredSchemaVersion=parseInt(row.value,10);
if(storedSchemaVersion===currentSchemaVersion){
return;
}
if(storedSchemaVersion>currentSchemaVersion){
returnlog.error(`sqlite messages schema version is higher than expected (${storedSchemaVersion} > ${currentSchemaVersion}). Is The Lounge out of date?`);
}
log.info(`sqlite messages schema version is out of date (${storedSchemaVersion} < ${currentSchemaVersion}). Running migrations if any.`);
this.database.serialize(()=>this.database.run("UPDATE options SET value = ? WHERE name = 'schema_version'",currentSchemaVersion));