1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-01-16 02:47:11 +02:00

Fix: Handle null values in Mailpit settings, set DeletedSize=0 if null

This commit is contained in:
Ralph Slooten 2024-03-02 00:40:51 +13:00
parent 23b1261cf9
commit 4fa8014735
2 changed files with 12 additions and 7 deletions

View File

@ -121,6 +121,11 @@ func dbApplyMigrations() error {
// These functions are used to migrate data formats/structure on startup.
func dataMigrations() {
// ensure DeletedSize has a value if empty
if SettingGet("DeletedSize") == "" {
_ = SettingPut("DeletedSize", "0")
}
migrateTagsToManyMany()
}

View File

@ -9,7 +9,7 @@ import (
// SettingGet returns a setting string value, blank is it does not exist
func SettingGet(k string) string {
var result string
var result sql.NullString
err := sqlf.From("settings").
Select("Value").To(&result).
Where("Key = ?", k).
@ -17,10 +17,10 @@ func SettingGet(k string) string {
QueryAndClose(nil, db, func(row *sql.Rows) {})
if err != nil {
logger.Log().Errorf("[db] %s", err.Error())
return result
return ""
}
return result
return result.String
}
// SettingPut sets a setting string value, inserting if new
@ -35,7 +35,7 @@ func SettingPut(k, v string) error {
// The total deleted message size as an int64 value
func getDeletedSize() int64 {
var result int64
var result sql.NullInt64
err := sqlf.From("settings").
Select("Value").To(&result).
Where("Key = ?", "DeletedSize").
@ -43,10 +43,10 @@ func getDeletedSize() int64 {
QueryAndClose(nil, db, func(row *sql.Rows) {})
if err != nil {
logger.Log().Errorf("[db] %s", err.Error())
return result
return 0
}
return result
return result.Int64
}
// The total raw non-compressed messages size in bytes of all messages in the database
@ -57,7 +57,7 @@ func totalMessagesSize() int64 {
QueryAndClose(nil, db, func(row *sql.Rows) {})
if err != nil {
logger.Log().Errorf("[db] %s", err.Error())
return result
return 0
}
return result