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:
Andrea Maria Piana 2020-07-30 08:26:19 +02:00
parent ec39bef088
commit eadf68325e
3 changed files with 24 additions and 2 deletions

View File

@ -1 +1 @@
0.56.2
0.56.3

View File

@ -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,

View File

@ -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)
}