@ -216,6 +216,16 @@ async function checkMigrations() {
else { logger . error ( 'Migration failed: 3.5->3.6+' ) ; }
}
// 4.1->4.2 migration
const add _description _migration _complete = false ; // db.get('add_description_migration_complete').value();
if ( ! add _description _migration _complete ) {
logger . info ( 'Beginning migration: 4.1->4.2+' )
const success = await addMetadataPropertyToDB ( 'description' ) ;
if ( success ) { logger . info ( '4.1->4.2+ migration complete!' ) ; }
else { logger . error ( 'Migration failed: 4.1->4.2+' ) ; }
}
return true ;
}
@ -251,6 +261,28 @@ async function runFilesToDBMigration() {
}
}
async function addMetadataPropertyToDB ( property _key ) {
try {
const dirs _to _check = db _api . getFileDirectoriesAndDBs ( ) ;
for ( const dir _to _check of dirs _to _check ) {
// recursively get all files in dir's path
const files = await utils . getDownloadedFilesByType ( dir _to _check . basePath , dir _to _check . type , true ) ;
for ( const file of files ) {
if ( file [ property _key ] ) {
dir _to _check . dbPath . find ( { id : file . id } ) . assign ( { [ property _key ] : file [ property _key ] } ) . write ( ) ;
}
}
}
// sets migration to complete
db . set ( 'add_description_migration_complete' , true ) . write ( ) ;
return true ;
} catch ( err ) {
logger . error ( err ) ;
return false ;
}
}
async function startServer ( ) {
if ( process . env . USING _HEROKU && process . env . PORT ) {
// default to heroku port if using heroku