mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
feat(migrate): invalid uploads type conversion
use with yarn migrate
This commit is contained in:
parent
2afdabb8aa
commit
8623687b42
@ -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).`
|
||||
|
Loading…
Reference in New Issue
Block a user