Fix audio null value
If a message was inserted before the migration the field audio_duration_ms would be set to NULL, and would not be serialized into go correctly, as uint is non-nullable. this commit fixes the issue by calling COALESCE on the value.
This commit is contained in:
parent
ec39bef088
commit
eadf68325e
|
@ -72,7 +72,7 @@ func (db sqlitePersistence) tableUserMessagesAllFieldsJoin() string {
|
|||
m1.sticker_pack,
|
||||
m1.sticker_hash,
|
||||
m1.image_base64,
|
||||
m1.audio_duration_ms,
|
||||
COALESCE(m1.audio_duration_ms,0),
|
||||
m1.audio_base64,
|
||||
m1.command_id,
|
||||
m1.command_value,
|
||||
|
|
|
@ -391,3 +391,25 @@ func insertMinimalMessage(p sqlitePersistence, id string) error {
|
|||
From: "me",
|
||||
}})
|
||||
}
|
||||
|
||||
// Regression test making sure that if audio_duration_ms is null, no error is thrown
|
||||
func TestMessagesAudioDurationMsNull(t *testing.T) {
|
||||
db, err := openTestDB()
|
||||
require.NoError(t, err)
|
||||
p := sqlitePersistence{db: db}
|
||||
id := "message-id-1"
|
||||
|
||||
err = insertMinimalMessage(p, id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = p.db.Exec("UPDATE user_messages SET audio_duration_ms = NULL")
|
||||
require.NoError(t, err)
|
||||
|
||||
m, err := p.MessagesByIDs([]string{id})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, m, 1)
|
||||
|
||||
m, _, err = p.MessageByChatID("chat-id", "", 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, m, 1)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue