mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
fix: inconsistent size field in DB !! yarn migrate
we used to store number directly into the string size field, and during the conversion it seemed to always add ".0" at the final string, probably because the driver or sqlite3 itself assumes float please run yarn migrate after pulling this commit if you skip converting the DB, file duplicates check will fail to function and in the future im planning to do size statistics in bigint, which will also fail if not converted
This commit is contained in:
parent
9d38c431dc
commit
38e673226f
@ -836,7 +836,7 @@ self.storeFilesToDb = async (req, res, user, infoMap) => {
|
||||
})
|
||||
.where({
|
||||
hash: info.data.hash,
|
||||
size: info.data.size
|
||||
size: String(info.data.size)
|
||||
})
|
||||
// Select expirydate to display expiration date of existing files as well
|
||||
.select('name', 'expirydate')
|
||||
@ -861,7 +861,7 @@ self.storeFilesToDb = async (req, res, user, infoMap) => {
|
||||
name: info.data.filename,
|
||||
original: info.data.originalname,
|
||||
type: info.data.mimetype,
|
||||
size: info.data.size,
|
||||
size: String(info.data.size),
|
||||
hash: info.data.hash,
|
||||
// Only disable if explicitly set to false in config
|
||||
ip: config.uploads.storeIP !== false ? req.ip : null,
|
||||
|
@ -70,6 +70,19 @@ const map = {
|
||||
})
|
||||
}
|
||||
|
||||
const files = 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) {
|
||||
const size = file.size.replace(/\.0$/, '')
|
||||
await db.table('files')
|
||||
.update('size', size)
|
||||
.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