From 17c697445dea7cddc830844c6b8a14ecf8ea6e47 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Thu, 12 May 2022 11:55:10 -0600 Subject: [PATCH] history sync: store timestamp when the message got put into the DB This will be useful for debugging issues with missing messages --- database/historysync.go | 6 +++--- ...2-history-sync-message-add-added-timestamp.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 database/upgrades/2022-05-12-history-sync-message-add-added-timestamp.go diff --git a/database/historysync.go b/database/historysync.go index eba4f8d..25ac7a8 100644 --- a/database/historysync.go +++ b/database/historysync.go @@ -249,10 +249,10 @@ func (hsq *HistorySyncQuery) NewMessageWithValues(userID id.UserID, conversation func (hsm *HistorySyncMessage) Insert() { _, err := hsm.db.Exec(` - INSERT INTO history_sync_message (user_mxid, conversation_id, message_id, timestamp, data) - VALUES ($1, $2, $3, $4, $5) + INSERT INTO history_sync_message (user_mxid, conversation_id, message_id, timestamp, data, inserted_time) + VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (user_mxid, conversation_id, message_id) DO NOTHING - `, hsm.UserID, hsm.ConversationID, hsm.MessageID, hsm.Timestamp, hsm.Data) + `, hsm.UserID, hsm.ConversationID, hsm.MessageID, hsm.Timestamp, hsm.Data, time.Now()) if err != nil { hsm.log.Warnfln("Failed to insert history sync message %s/%s: %v", hsm.ConversationID, hsm.Timestamp, err) } diff --git a/database/upgrades/2022-05-12-history-sync-message-add-added-timestamp.go b/database/upgrades/2022-05-12-history-sync-message-add-added-timestamp.go new file mode 100644 index 0000000..1f701ea --- /dev/null +++ b/database/upgrades/2022-05-12-history-sync-message-add-added-timestamp.go @@ -0,0 +1,16 @@ +package upgrades + +import ( + "database/sql" +) + +func init() { + upgrades[46] = upgrade{"Add inserted time to history sync message", func(tx *sql.Tx, ctx context) error { + // Add the inserted time TIMESTAMP column to history_sync_message + _, err := tx.Exec(` + ALTER TABLE history_sync_message + ADD COLUMN inserted_time TIMESTAMP + `) + return err + }} +}