summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go70
-rw-r--r--store/sql_channel_store_test.go8
-rw-r--r--store/sql_post_store.go18
-rw-r--r--store/sql_team_store.go5
-rw-r--r--store/sql_user_store.go2
-rw-r--r--store/store.go1
6 files changed, 26 insertions, 78 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 2d62b8614..a9f99bd67 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -4,7 +4,6 @@
package store
import (
- l4g "code.google.com/p/log4go"
"github.com/go-gorp/gorp"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
@@ -40,55 +39,6 @@ func NewSqlChannelStore(sqlStore *SqlStore) ChannelStore {
}
func (s SqlChannelStore) UpgradeSchemaIfNeeded() {
-
- // REMOVE AFTER 1.2 SHIP see PLT-828
- if s.CreateColumnIfNotExists("ChannelMembers", "NotifyProps", "varchar(2000)", "varchar(2000)", "{}") {
- // populate NotifyProps from existing NotifyLevel field
-
- // set default values
- _, err := s.GetMaster().Exec(
- `UPDATE
- ChannelMembers
- SET
- NotifyProps = CONCAT('{"desktop":"', CONCAT(NotifyLevel, '","mark_unread":"` + model.CHANNEL_MARK_UNREAD_ALL + `"}'))`)
- if err != nil {
- l4g.Error("Unable to set default values for ChannelMembers.NotifyProps")
- l4g.Error(err.Error())
- }
-
- // assume channels with all notifications enabled are just using the default settings
- _, err = s.GetMaster().Exec(
- `UPDATE
- ChannelMembers
- SET
- NotifyProps = '{"desktop":"` + model.CHANNEL_NOTIFY_DEFAULT + `","mark_unread":"` + model.CHANNEL_MARK_UNREAD_ALL + `"}'
- WHERE
- NotifyLevel = '` + model.CHANNEL_NOTIFY_ALL + `'`)
- if err != nil {
- l4g.Error("Unable to set values for ChannelMembers.NotifyProps when members previously had notifyLevel=all")
- l4g.Error(err.Error())
- }
-
- // set quiet mode channels to have no notifications and only mark the channel unread on mentions
- _, err = s.GetMaster().Exec(
- `UPDATE
- ChannelMembers
- SET
- NotifyProps = '{"desktop":"` + model.CHANNEL_NOTIFY_NONE + `","mark_unread":"` + model.CHANNEL_MARK_UNREAD_MENTION + `"}'
- WHERE
- NotifyLevel = 'quiet'`)
- if err != nil {
- l4g.Error("Unable to set values for ChannelMembers.NotifyProps when members previously had notifyLevel=quiet")
- l4g.Error(err.Error())
- }
-
- s.RemoveColumnIfExists("ChannelMembers", "NotifyLevel")
- }
-
- // BEGIN REMOVE AFTER 1.2.0
- s.RenameColumnIfExists("Channels", "Description", "Header", "varchar(1024)")
- s.CreateColumnIfNotExists("Channels", "Purpose", "varchar(1024)", "varchar(1024)", "")
- // END REMOVE AFTER 1.2.0
}
func (s SqlChannelStore) CreateIndexesIfNotExists() {
@@ -592,6 +542,26 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel
return storeChannel
}
+func (s SqlChannelStore) GetMemberCount(channelId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ count, err := s.GetReplica().SelectInt("SELECT count(*) FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId})
+ if err != nil {
+ result.Err = model.NewAppError("SqlChannelStore.GetMemberCount", "We couldn't get the channel member count", "channel_id="+channelId+", "+err.Error())
+ } else {
+ result.Data = count
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (s SqlChannelStore) GetExtraMembers(channelId string, limit int) StoreChannel {
storeChannel := make(StoreChannel)
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index f6a0fb713..8662fcbd3 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -339,15 +339,15 @@ func TestChannelMemberStore(t *testing.T) {
t.Fatal("Member update time incorrect")
}
- members := (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember)
- if len(members) != 2 {
+ count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
+ if count != 2 {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().RemoveMember(o2.ChannelId, o2.UserId))
- members = (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember)
- if len(members) != 1 {
+ count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
+ if count != 1 {
t.Fatal("should have removed 1 member")
}
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 3460fca92..f800367cb 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -9,10 +9,8 @@ import (
"strconv"
"strings"
- l4g "code.google.com/p/log4go"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
- "time"
)
type SqlPostStore struct {
@@ -40,21 +38,7 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
}
func (s SqlPostStore) UpgradeSchemaIfNeeded() {
- colType := s.GetColumnDataType("Posts", "Props")
- if colType != "text" {
-
- query := "ALTER TABLE Posts MODIFY COLUMN Props TEXT"
- if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
- query = "ALTER TABLE Posts ALTER COLUMN Props TYPE text"
- }
-
- _, err := s.GetMaster().Exec(query)
- if err != nil {
- l4g.Critical("Failed to alter column Posts.Props to TEXT: " + err.Error())
- time.Sleep(time.Second)
- panic("Failed to alter column Posts.Props to TEXT: " + err.Error())
- }
- }
+ s.RemoveColumnIfExists("Posts", "ImgCount") // remove after 1.3 release
}
func (s SqlPostStore) CreateIndexesIfNotExists() {
diff --git a/store/sql_team_store.go b/store/sql_team_store.go
index e0f95fa7e..1a0aeabde 100644
--- a/store/sql_team_store.go
+++ b/store/sql_team_store.go
@@ -30,11 +30,6 @@ func NewSqlTeamStore(sqlStore *SqlStore) TeamStore {
}
func (s SqlTeamStore) UpgradeSchemaIfNeeded() {
- // REMOVE AFTER 1.2 SHIP see PLT-828
- s.RemoveColumnIfExists("Teams", "AllowValet")
- s.CreateColumnIfNotExists("Teams", "InviteId", "varchar(32)", "varchar(32)", "")
- s.CreateColumnIfNotExists("Teams", "AllowOpenInvite", "tinyint(1)", "boolean", "0")
- s.CreateColumnIfNotExists("Teams", "AllowTeamListing", "tinyint(1)", "boolean", "0")
}
func (s SqlTeamStore) CreateIndexesIfNotExists() {
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 686949a4d..d38b5c214 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -41,8 +41,6 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore {
}
func (us SqlUserStore) UpgradeSchemaIfNeeded() {
- // REMOVE AFTER 1.2 SHIP see PLT-828
- us.CreateColumnIfNotExists("Users", "ThemeProps", "varchar(2000)", "character varying(2000)", "{}")
}
func (us SqlUserStore) CreateIndexesIfNotExists() {
diff --git a/store/store.go b/store/store.go
index ce4d90883..13b59b582 100644
--- a/store/store.go
+++ b/store/store.go
@@ -70,6 +70,7 @@ type ChannelStore interface {
UpdateMember(member *model.ChannelMember) StoreChannel
GetMembers(channelId string) StoreChannel
GetMember(channelId string, userId string) StoreChannel
+ GetMemberCount(channelId string) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
GetExtraMembers(channelId string, limit int) StoreChannel
CheckPermissionsTo(teamId string, channelId string, userId string) StoreChannel