summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-08-24 13:51:45 +0200
committerGitHub <noreply@github.com>2018-08-24 13:51:45 +0200
commitf9dbea6d860a71d8756d69b80a5fc0fe91d6514b (patch)
tree344ee7fdbdbd688feaa55c1d20914fb9d4ebf4af /store
parenta63c68be35f3afd400853eb54cec9968b1344bc4 (diff)
downloadchat-f9dbea6d860a71d8756d69b80a5fc0fe91d6514b.tar.gz
chat-f9dbea6d860a71d8756d69b80a5fc0fe91d6514b.tar.bz2
chat-f9dbea6d860a71d8756d69b80a5fc0fe91d6514b.zip
Fix sampledata reset LastPostAt when the channels are empty (#9295)
Diffstat (limited to 'store')
-rw-r--r--store/sqlstore/channel_store.go9
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)
}
})