From 8623687b42f2bbd407fa0fe2ad30159f296a33d6 Mon Sep 17 00:00:00 2001 From: Bobby Date: Thu, 6 Oct 2022 04:30:34 +0700 Subject: [PATCH] feat(migrate): invalid uploads type conversion use with yarn migrate --- scripts/migrate.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/migrate.js b/scripts/migrate.js index eb6037a..b029f4f 100644 --- a/scripts/migrate.js +++ b/scripts/migrate.js @@ -65,11 +65,11 @@ const map = { }) } - const files = await db.table('files') + const filesOutdatedSize = await db.table('files') .where('size', 'like', '%.0') - if (files.length) { - console.log(`Found ${files.length} files with outdated "size" field, converting\u2026`) - for (const file of files) { + if (filesOutdatedSize.length) { + console.log(`Found ${filesOutdatedSize.length} files with outdated "size" field, converting\u2026`) + for (const file of filesOutdatedSize) { const size = file.size.replace(/\.0$/, '') await db.table('files') .update('size', size) @@ -78,6 +78,19 @@ const map = { } } + const filesMissingType = await db.table('files') + .where('type', '') + .orWhereNull('type') + if (filesMissingType.length) { + console.log(`Found ${filesMissingType.length} files with invalid "type" field, converting\u2026`) + for (const file of filesMissingType) { + await db.table('files') + .update('type', 'application/octet-stream') + .where('id', file.id) + done++ + } + } + let status = 'Database migration was not required.' if (done) { status = `Completed ${done} database migration task(s).`