diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-08-24 13:51:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-24 13:51:45 +0200 |
commit | f9dbea6d860a71d8756d69b80a5fc0fe91d6514b (patch) | |
tree | 344ee7fdbdbd688feaa55c1d20914fb9d4ebf4af /store/sqlstore | |
parent | a63c68be35f3afd400853eb54cec9968b1344bc4 (diff) | |
download | chat-f9dbea6d860a71d8756d69b80a5fc0fe91d6514b.tar.gz chat-f9dbea6d860a71d8756d69b80a5fc0fe91d6514b.tar.bz2 chat-f9dbea6d860a71d8756d69b80a5fc0fe91d6514b.zip |
Fix sampledata reset LastPostAt when the channels are empty (#9295)
Diffstat (limited to 'store/sqlstore')
-rw-r--r-- | store/sqlstore/channel_store.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 97f60dda0..6d0c7353f 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -1924,7 +1924,14 @@ func (s SqlChannelStore) ClearAllCustomRoleAssignments() store.StoreChannel { func (s SqlChannelStore) ResetLastPostAt() store.StoreChannel { return store.Do(func(result *store.StoreResult) { - if _, err := s.GetMaster().Exec("UPDATE Channels SET LastPostAt = (SELECT UpdateAt FROM Posts WHERE ChannelId = Channels.Id ORDER BY UpdateAt DESC LIMIT 1);"); err != nil { + var query string + if s.DriverName() == model.DATABASE_DRIVER_POSTGRES { + query = "UPDATE Channels SET LastPostAt = COALESCE((SELECT UpdateAt FROM Posts WHERE ChannelId = Channels.Id ORDER BY UpdateAt DESC LIMIT 1), Channels.CreateAt);" + } else { + query = "UPDATE Channels SET LastPostAt = IFNULL((SELECT UpdateAt FROM Posts WHERE ChannelId = Channels.Id ORDER BY UpdateAt DESC LIMIT 1), Channels.CreateAt);" + } + + if _, err := s.GetMaster().Exec(query); err != nil { result.Err = model.NewAppError("SqlChannelStore.ResetLastPostAt", "store.sql_channel.reset_last_post_at.app_error", nil, err.Error(), http.StatusInternalServerError) } }) |