Added better error checking to migration schema statics.
This commit is contained in:
parent
9fda308306
commit
ad0dd6bdbb
|
|
@ -24,6 +24,7 @@ const {mongoose} = require('mongoose');
|
||||||
const config = require('../../../config.json');
|
const config = require('../../../config.json');
|
||||||
const {userModel} = require('../user/userSchema');
|
const {userModel} = require('../user/userSchema');
|
||||||
const permissionModel = require('../permissionSchema');
|
const permissionModel = require('../permissionSchema');
|
||||||
|
const loggerUtils = require('../../utils/loggerUtils');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,11 +67,15 @@ const migrationSchema = new mongoose.Schema({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//TODO: before next commit, add error checking to the ingestLegacy statics down below
|
||||||
|
//Also add a warning for the fail condition in ingestLegacyDump that bails out when missing files
|
||||||
|
|
||||||
//statics
|
//statics
|
||||||
/**
|
/**
|
||||||
* Static method for ingesting data dump from legacy cytube/fore.st server
|
* Static method for ingesting data dump from legacy cytube/fore.st server
|
||||||
*/
|
*/
|
||||||
migrationSchema.statics.ingestLegacyDump = async function(){
|
migrationSchema.statics.ingestLegacyDump = async function(){
|
||||||
|
try{
|
||||||
//If migration is disabled
|
//If migration is disabled
|
||||||
if(!config.migrate){
|
if(!config.migrate){
|
||||||
//BAIL!
|
//BAIL!
|
||||||
|
|
@ -87,6 +92,7 @@ migrationSchema.statics.ingestLegacyDump = async function(){
|
||||||
await fs.stat(userDump);
|
await fs.stat(userDump);
|
||||||
//If we caught an error (most likely it's missing)
|
//If we caught an error (most likely it's missing)
|
||||||
}catch(err){
|
}catch(err){
|
||||||
|
loggerUtils.consoleWarn("No migration files detected! Pleas provide legacy migration files or disable migration from config.json!");
|
||||||
//BAIL!
|
//BAIL!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +108,9 @@ migrationSchema.statics.ingestLegacyDump = async function(){
|
||||||
//Ingest the legacy user profile
|
//Ingest the legacy user profile
|
||||||
this.ingestLegacyUser(line);
|
this.ingestLegacyUser(line);
|
||||||
}
|
}
|
||||||
|
}catch(err){
|
||||||
|
return loggerUtils.localExceptionHandler(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,6 +118,7 @@ migrationSchema.statics.ingestLegacyDump = async function(){
|
||||||
* @param {String} rawProfile - Line of text contianing raw profile dump
|
* @param {String} rawProfile - Line of text contianing raw profile dump
|
||||||
*/
|
*/
|
||||||
migrationSchema.statics.ingestLegacyUser = async function(rawProfile){
|
migrationSchema.statics.ingestLegacyUser = async function(rawProfile){
|
||||||
|
try{
|
||||||
//If migration is disabled
|
//If migration is disabled
|
||||||
if(!config.migrate){
|
if(!config.migrate){
|
||||||
//BAIL!
|
//BAIL!
|
||||||
|
|
@ -120,6 +130,8 @@ migrationSchema.statics.ingestLegacyUser = async function(rawProfile){
|
||||||
|
|
||||||
//If we have an invalid line
|
//If we have an invalid line
|
||||||
if(profileMatches <= 0){
|
if(profileMatches <= 0){
|
||||||
|
loggerUtils.consoleWarn('Bad profile detected in legacy dump:');
|
||||||
|
loggerUtils.consoleWarn(rawProfile);
|
||||||
//BAIL!
|
//BAIL!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -143,6 +155,8 @@ migrationSchema.statics.ingestLegacyUser = async function(rawProfile){
|
||||||
|
|
||||||
//If profile array is the wrong length
|
//If profile array is the wrong length
|
||||||
if(profileArray.length != 10){
|
if(profileArray.length != 10){
|
||||||
|
loggerUtils.consoleWarn('Bad profile detected in legacy dump:');
|
||||||
|
loggerUtils.consoleWarn(profileArray);
|
||||||
//BAIL!
|
//BAIL!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +168,7 @@ migrationSchema.statics.ingestLegacyUser = async function(rawProfile){
|
||||||
//If we found the user in the database
|
//If we found the user in the database
|
||||||
if(foundMigration != null || foundUser != null){
|
if(foundMigration != null || foundUser != null){
|
||||||
//Scream
|
//Scream
|
||||||
console.log(`Found legacy user ${profileArray[1]} in database, skipping migration!`);
|
loggerUtils.consoleWarn(`Found legacy user ${profileArray[1]} in database, skipping migration!`);
|
||||||
//BAIL!
|
//BAIL!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -185,6 +199,9 @@ migrationSchema.statics.ingestLegacyUser = async function(rawProfile){
|
||||||
|
|
||||||
//Let the world know of our triumph!
|
//Let the world know of our triumph!
|
||||||
console.log(`Legacy user profile ${migrationProfile.user} migrated successfully!`);
|
console.log(`Legacy user profile ${migrationProfile.user} migrated successfully!`);
|
||||||
|
}catch(err){
|
||||||
|
return loggerUtils.localExceptionHandler(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = mongoose.model("migration", migrationSchema);
|
module.exports = mongoose.model("migration", migrationSchema);
|
||||||
Loading…
Reference in a new issue