Added ability to add more metadata to db through migrations, and added scaffolding for supporting description and play count in the player component

This commit is contained in:
Isaac Abadi
2020-12-09 17:28:00 -05:00
parent f425b9842f
commit c6fc5352c5
4 changed files with 58 additions and 2 deletions

View File

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