feat(migrate): invalid uploads type conversion

use with yarn migrate
This commit is contained in:
Bobby 2022-10-06 04:30:34 +07:00
parent 2afdabb8aa
commit 8623687b42
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09

View File

@ -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).`