Fixes mm-1420 adding postgres support
Этот коммит содержится в:
@@ -31,7 +31,7 @@ func (s SqlAuditStore) UpgradeSchemaIfNeeded() {
|
||||
}
|
||||
|
||||
func (s SqlAuditStore) CreateIndexesIfNotExists() {
|
||||
s.CreateIndexIfNotExists("idx_user_id", "Audits", "UserId")
|
||||
s.CreateIndexIfNotExists("idx_audits_user_id", "Audits", "UserId")
|
||||
}
|
||||
|
||||
func (s SqlAuditStore) Save(audit *model.Audit) StoreChannel {
|
||||
@@ -73,8 +73,8 @@ func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel {
|
||||
}
|
||||
|
||||
var audits model.Audits
|
||||
if _, err := s.GetReplica().Select(&audits, "SELECT * FROM Audits WHERE UserId = ? ORDER BY CreateAt DESC LIMIT ?",
|
||||
user_id, limit); err != nil {
|
||||
if _, err := s.GetReplica().Select(&audits, "SELECT * FROM Audits WHERE UserId = :user_id ORDER BY CreateAt DESC LIMIT :limit",
|
||||
map[string]interface{}{"user_id": user_id, "limit": limit}); err != nil {
|
||||
result.Err = model.NewAppError("SqlAuditStore.Get", "We encounted an error finding the audits", "user_id="+user_id)
|
||||
} else {
|
||||
result.Data = audits
|
||||
|
||||
@@ -37,11 +37,14 @@ func NewSqlChannelStore(sqlStore *SqlStore) ChannelStore {
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) UpgradeSchemaIfNeeded() {
|
||||
s.CreateColumnIfNotExists("ChannelMembers", "LastUpdateAt", "NotifyLevel", "bigint(20)", "0") // Remove after 6/7/2015 prod push
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) CreateIndexesIfNotExists() {
|
||||
s.CreateIndexIfNotExists("idx_team_id", "Channels", "TeamId")
|
||||
s.CreateIndexIfNotExists("idx_channels_team_id", "Channels", "TeamId")
|
||||
s.CreateIndexIfNotExists("idx_channels_name", "Channels", "Name")
|
||||
|
||||
s.CreateIndexIfNotExists("idx_channelmembers_channel_id", "ChannelMembers", "ChannelId")
|
||||
s.CreateIndexIfNotExists("idx_channelmembers_user_id", "ChannelMembers", "UserId")
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) Save(channel *model.Channel) StoreChannel {
|
||||
@@ -65,7 +68,7 @@ func (s SqlChannelStore) Save(channel *model.Channel) StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
if count, err := s.GetMaster().SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = ? AND DeleteAt = 0 AND (Type ='O' || Type ='P')", channel.TeamId); err != nil {
|
||||
if count, err := s.GetMaster().SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", map[string]interface{}{"TeamId": channel.TeamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Save", "Failed to get current channel count", "teamId="+channel.TeamId+", "+err.Error())
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
@@ -167,7 +170,7 @@ func (s SqlChannelStore) Delete(channelId string, time int64) StoreChannel {
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
_, err := s.GetMaster().Exec("Update Channels SET DeleteAt = ?, UpdateAt = ? WHERE Id = ?", time, time, channelId)
|
||||
_, err := s.GetMaster().Exec("Update Channels SET DeleteAt = "+s.GetMaster().Dialect.BindVar(0)+", UpdateAt = "+s.GetMaster().Dialect.BindVar(1)+" WHERE Id = "+s.GetMaster().Dialect.BindVar(2), time, time, channelId)
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.Delete", "We couldn't delete the channel", "id="+channelId+", err="+err.Error())
|
||||
}
|
||||
@@ -191,7 +194,7 @@ func (s SqlChannelStore) GetChannels(teamId string, userId string) StoreChannel
|
||||
result := StoreResult{}
|
||||
|
||||
var data []channelWithMember
|
||||
_, err := s.GetReplica().Select(&data, "SELECT * FROM Channels, ChannelMembers WHERE Id = ChannelId AND TeamId = ? AND UserId = ? AND DeleteAt = 0 ORDER BY DisplayName", teamId, userId)
|
||||
_, err := s.GetReplica().Select(&data, "SELECT * FROM Channels, ChannelMembers WHERE Id = ChannelId AND TeamId = :TeamId AND UserId = :UserId AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetChannels", "We couldn't get the channels", "teamId="+teamId+", userId="+userId+", err="+err.Error())
|
||||
@@ -230,8 +233,8 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
|
||||
FROM
|
||||
Channels
|
||||
WHERE
|
||||
TeamId = ?
|
||||
AND Type IN ("O")
|
||||
TeamId = :TeamId1
|
||||
AND Type IN ('O')
|
||||
AND DeleteAt = 0
|
||||
AND Id NOT IN (SELECT
|
||||
Channels.Id
|
||||
@@ -240,11 +243,11 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
|
||||
ChannelMembers
|
||||
WHERE
|
||||
Id = ChannelId
|
||||
AND TeamId = ?
|
||||
AND UserId = ?
|
||||
AND TeamId = :TeamId2
|
||||
AND UserId = :UserId
|
||||
AND DeleteAt = 0)
|
||||
ORDER BY DisplayName`,
|
||||
teamId, teamId, userId)
|
||||
map[string]interface{}{"TeamId1": teamId, "TeamId2": teamId, "UserId": userId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetMoreChannels", "We couldn't get the channels", "teamId="+teamId+", userId="+userId+", err="+err.Error())
|
||||
@@ -267,7 +270,7 @@ func (s SqlChannelStore) GetByName(teamId string, name string) StoreChannel {
|
||||
|
||||
channel := model.Channel{}
|
||||
|
||||
if err := s.GetReplica().SelectOne(&channel, "SELECT * FROM Channels WHERE TeamId=? AND Name=? AND DeleteAt = 0", teamId, name); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&channel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name= :Name AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetByName", "We couldn't find the existing channel", "teamId="+teamId+", "+"name="+name+", "+err.Error())
|
||||
} else {
|
||||
result.Data = &channel
|
||||
@@ -316,7 +319,7 @@ func (s SqlChannelStore) GetMembers(channelId string) StoreChannel {
|
||||
result := StoreResult{}
|
||||
|
||||
var members []model.ChannelMember
|
||||
_, err := s.GetReplica().Select(&members, "SELECT * FROM ChannelMembers WHERE ChannelId = ?", channelId)
|
||||
_, err := s.GetReplica().Select(&members, "SELECT * FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetMembers", "We couldn't get the channel members", "channel_id="+channelId+err.Error())
|
||||
} else {
|
||||
@@ -337,7 +340,7 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel
|
||||
result := StoreResult{}
|
||||
|
||||
var member model.ChannelMember
|
||||
err := s.GetReplica().SelectOne(&member, "SELECT * FROM ChannelMembers WHERE ChannelId = ? AND UserId = ?", channelId, userId)
|
||||
err := s.GetReplica().SelectOne(&member, "SELECT * FROM ChannelMembers WHERE ChannelId = :ChannelId AND UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetMember", "We couldn't get the channel member", "channel_id="+channelId+"user_id="+userId+","+err.Error())
|
||||
} else {
|
||||
@@ -358,7 +361,7 @@ func (s SqlChannelStore) GetExtraMembers(channelId string, limit int) StoreChann
|
||||
result := StoreResult{}
|
||||
|
||||
var members []model.ExtraMember
|
||||
_, err := s.GetReplica().Select(&members, "SELECT Id, FullName, Email, ChannelMembers.Roles, Username FROM ChannelMembers, Users WHERE ChannelMembers.UserId = Users.Id AND ChannelId = ? LIMIT ?", channelId, limit)
|
||||
_, err := s.GetReplica().Select(&members, "SELECT Id, FullName, Email, ChannelMembers.Roles, Username FROM ChannelMembers, Users WHERE ChannelMembers.UserId = Users.Id AND ChannelId = :ChannelId LIMIT :Limit", map[string]interface{}{"ChannelId": channelId, "Limit": limit})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetExtraMembers", "We couldn't get the extra info for channel members", "channel_id="+channelId+", "+err.Error())
|
||||
} else {
|
||||
@@ -381,7 +384,7 @@ func (s SqlChannelStore) RemoveMember(channelId string, userId string) StoreChan
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
_, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = ? AND UserId = ?", channelId, userId)
|
||||
_, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = :ChannelId AND UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.RemoveMember", "We couldn't remove the channel member", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
|
||||
}
|
||||
@@ -407,11 +410,11 @@ func (s SqlChannelStore) CheckPermissionsTo(teamId string, channelId string, use
|
||||
ChannelMembers
|
||||
WHERE
|
||||
Channels.Id = ChannelMembers.ChannelId
|
||||
AND Channels.TeamId = ?
|
||||
AND Channels.TeamId = :TeamId
|
||||
AND Channels.DeleteAt = 0
|
||||
AND ChannelMembers.ChannelId = ?
|
||||
AND ChannelMembers.UserId = ?`,
|
||||
teamId, channelId, userId)
|
||||
AND ChannelMembers.ChannelId = :ChannelId
|
||||
AND ChannelMembers.UserId = :UserId`,
|
||||
map[string]interface{}{"TeamId": teamId, "ChannelId": channelId, "UserId": userId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.CheckPermissionsTo", "We couldn't check the permissions", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
|
||||
} else {
|
||||
@@ -439,11 +442,11 @@ func (s SqlChannelStore) CheckPermissionsToByName(teamId string, channelName str
|
||||
ChannelMembers
|
||||
WHERE
|
||||
Channels.Id = ChannelMembers.ChannelId
|
||||
AND Channels.TeamId = ?
|
||||
AND Channels.Name = ?
|
||||
AND Channels.TeamId = :TeamId
|
||||
AND Channels.Name = :Name
|
||||
AND Channels.DeleteAt = 0
|
||||
AND ChannelMembers.UserId = ?`,
|
||||
teamId, channelName, userId)
|
||||
AND ChannelMembers.UserId = :UserId`,
|
||||
map[string]interface{}{"TeamId": teamId, "Name": channelName, "UserId": userId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.CheckPermissionsToByName", "We couldn't check the permissions", "channel_id="+channelName+", user_id="+userId+", "+err.Error())
|
||||
} else {
|
||||
@@ -469,10 +472,10 @@ func (s SqlChannelStore) CheckOpenChannelPermissions(teamId string, channelId st
|
||||
FROM
|
||||
Channels
|
||||
WHERE
|
||||
Channels.Id = ?
|
||||
AND Channels.TeamId = ?
|
||||
AND Channels.Type = ?`,
|
||||
channelId, teamId, model.CHANNEL_OPEN)
|
||||
Channels.Id = :ChannelId
|
||||
AND Channels.TeamId = :TeamId
|
||||
AND Channels.Type = :ChannelType`,
|
||||
map[string]interface{}{"ChannelId": channelId, "TeamId": teamId, "ChannelType": model.CHANNEL_OPEN})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.CheckOpenChannelPermissions", "We couldn't check the permissions", "channel_id="+channelId+", "+err.Error())
|
||||
} else {
|
||||
@@ -494,17 +497,19 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) Sto
|
||||
|
||||
_, err := s.GetMaster().Exec(
|
||||
`UPDATE
|
||||
ChannelMembers, Channels
|
||||
ChannelMembers
|
||||
SET
|
||||
ChannelMembers.MentionCount = 0,
|
||||
ChannelMembers.MsgCount = Channels.TotalMsgCount,
|
||||
ChannelMembers.LastViewedAt = Channels.LastPostAt,
|
||||
ChannelMembers.LastUpdateAt = Channels.LastPostAt
|
||||
MentionCount = 0,
|
||||
MsgCount = Channels.TotalMsgCount,
|
||||
LastViewedAt = Channels.LastPostAt,
|
||||
LastUpdateAt = Channels.LastPostAt
|
||||
FROM
|
||||
Channels
|
||||
WHERE
|
||||
Channels.Id = ChannelMembers.ChannelId
|
||||
AND UserId = ?
|
||||
AND ChannelId = ?`,
|
||||
userId, channelId)
|
||||
AND UserId = :UserId
|
||||
AND ChannelId = :ChannelId`,
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.UpdateLastViewedAt", "We couldn't update the last viewed at time", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
|
||||
}
|
||||
@@ -528,9 +533,9 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string)
|
||||
SET
|
||||
MentionCount = MentionCount + 1
|
||||
WHERE
|
||||
UserId = ?
|
||||
AND ChannelId = ?`,
|
||||
userId, channelId)
|
||||
UserId = :UserId
|
||||
AND ChannelId = :ChannelId`,
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.IncrementMentionCount", "We couldn't increment the mention count", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
|
||||
}
|
||||
@@ -554,12 +559,12 @@ func (s SqlChannelStore) UpdateNotifyLevel(channelId, userId, notifyLevel string
|
||||
`UPDATE
|
||||
ChannelMembers
|
||||
SET
|
||||
NotifyLevel = ?,
|
||||
LastUpdateAt = ?
|
||||
NotifyLevel = :NotifyLevel,
|
||||
LastUpdateAt = :LastUpdateAt
|
||||
WHERE
|
||||
UserId = ?
|
||||
AND ChannelId = ?`,
|
||||
notifyLevel, updateAt, userId, channelId)
|
||||
UserId = :UserId
|
||||
AND ChannelId = :ChannelId`,
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId, "NotifyLevel": notifyLevel, "LastUpdateAt": updateAt})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.UpdateNotifyLevel", "We couldn't update the notify level", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ func TestChannelStoreUpdateLastViewedAt(t *testing.T) {
|
||||
|
||||
err := (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, m1.UserId)).Err
|
||||
if err != nil {
|
||||
t.Fatal("failed to update")
|
||||
t.Fatal("failed to update", err)
|
||||
}
|
||||
|
||||
err = (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, "missing id")).Err
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/go-gorp/gorp"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"io"
|
||||
@@ -105,6 +106,8 @@ func setupConnection(con_type string, driver string, dataSource string, maxIdle
|
||||
dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.SqliteDialect{}}
|
||||
} else if driver == "mysql" {
|
||||
dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8"}}
|
||||
} else if driver == "postgres" {
|
||||
dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.PostgresDialect{}}
|
||||
} else {
|
||||
l4g.Critical("Failed to create dialect specific driver")
|
||||
time.Sleep(time.Second)
|
||||
@@ -118,9 +121,31 @@ func setupConnection(con_type string, driver string, dataSource string, maxIdle
|
||||
return dbmap
|
||||
}
|
||||
|
||||
func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool {
|
||||
count, err := ss.GetMaster().SelectInt(
|
||||
`SELECT
|
||||
func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, colType string, defaultValue string) bool {
|
||||
|
||||
// SELECT column_name
|
||||
// FROM information_schema.columns
|
||||
// WHERE table_name='your_table' and column_name='your_column';
|
||||
|
||||
var count int64
|
||||
var err error
|
||||
|
||||
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||
|
||||
count, err = ss.GetMaster().SelectInt(
|
||||
`SELECT
|
||||
COUNT(0) AS column_exists
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
WHERE
|
||||
TABLE_NAME = $1
|
||||
AND COLUMN_NAME = $2`,
|
||||
tableName,
|
||||
columnName,
|
||||
)
|
||||
} else if utils.Cfg.SqlSettings.DriverName == "mysql" {
|
||||
count, err = ss.GetMaster().SelectInt(
|
||||
`SELECT
|
||||
COUNT(0) AS column_exists
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
@@ -128,9 +153,11 @@ func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = ?
|
||||
AND COLUMN_NAME = ?`,
|
||||
tableName,
|
||||
columnName,
|
||||
)
|
||||
tableName,
|
||||
columnName,
|
||||
)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to check if column exists %v", err)
|
||||
time.Sleep(time.Second)
|
||||
@@ -141,7 +168,7 @@ func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
return false
|
||||
}
|
||||
|
||||
_, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + colType + " DEFAULT '" + defaultValue + "'" + " AFTER " + afterName)
|
||||
_, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + colType + " DEFAULT '" + defaultValue + "'")
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to create column %v", err)
|
||||
time.Sleep(time.Second)
|
||||
@@ -193,27 +220,55 @@ func (ss SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName st
|
||||
}
|
||||
|
||||
func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, fullText bool) {
|
||||
count, err := ss.GetMaster().SelectInt("SELECT COUNT(0) AS index_exists FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() and table_name = ? AND index_name = ?", tableName, indexName)
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to check index", err)
|
||||
|
||||
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||
_, err := ss.GetMaster().SelectStr("SELECT to_regclass($1)", indexName)
|
||||
// It should fail if the index does not exist
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
query := ""
|
||||
if fullText {
|
||||
query = "CREATE INDEX " + indexName + " ON " + tableName + " USING gin(to_tsvector('english', " + columnName + "))"
|
||||
} else {
|
||||
query = "CREATE INDEX " + indexName + " ON " + tableName + " (" + columnName + ")"
|
||||
}
|
||||
|
||||
_, err = ss.GetMaster().Exec(query)
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to create index %v", err)
|
||||
time.Sleep(time.Second)
|
||||
panic("Failed to create index " + err.Error())
|
||||
}
|
||||
} else if utils.Cfg.SqlSettings.DriverName == "mysql" {
|
||||
|
||||
count, err := ss.GetMaster().SelectInt("SELECT COUNT(0) AS index_exists FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() and table_name = ? AND index_name = ?", tableName, indexName)
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to check index %v", err)
|
||||
time.Sleep(time.Second)
|
||||
panic("Failed to check index " + err.Error())
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
fullTextIndex := ""
|
||||
if fullText {
|
||||
fullTextIndex = " FULLTEXT "
|
||||
}
|
||||
|
||||
_, err = ss.GetMaster().Exec("CREATE " + fullTextIndex + " INDEX " + indexName + " ON " + tableName + " (" + columnName + ")")
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to create index %v", err)
|
||||
time.Sleep(time.Second)
|
||||
panic("Failed to create index " + err.Error())
|
||||
}
|
||||
} else {
|
||||
l4g.Critical("Failed to create index because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
panic("Failed to check index" + err.Error())
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
fullTextIndex := ""
|
||||
if fullText {
|
||||
fullTextIndex = " FULLTEXT "
|
||||
}
|
||||
|
||||
_, err = ss.GetMaster().Exec("CREATE " + fullTextIndex + " INDEX " + indexName + " ON " + tableName + " (" + columnName + ")")
|
||||
if err != nil {
|
||||
l4g.Critical("Failed to create index", err)
|
||||
time.Sleep(time.Second)
|
||||
panic("Failed to create index " + err.Error())
|
||||
panic("Failed to create index because of missing driver")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ package store
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -30,11 +29,6 @@ func NewSqlTeamStore(sqlStore *SqlStore) TeamStore {
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) UpgradeSchemaIfNeeded() {
|
||||
defaultValue := "0"
|
||||
if utils.Cfg.TeamSettings.AllowValetDefault {
|
||||
defaultValue = "1"
|
||||
}
|
||||
s.CreateColumnIfNotExists("Teams", "AllowValet", "AllowedDomains", "tinyint(1)", defaultValue)
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) CreateIndexesIfNotExists() {
|
||||
|
||||
@@ -40,7 +40,8 @@ func (s SqlUserStore) UpgradeSchemaIfNeeded() {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) CreateIndexesIfNotExists() {
|
||||
us.CreateIndexIfNotExists("idx_team_id", "Users", "TeamId")
|
||||
us.CreateIndexIfNotExists("idx_users_team_id", "Users", "TeamId")
|
||||
us.CreateIndexIfNotExists("idx_users_email", "Users", "Email")
|
||||
}
|
||||
|
||||
func (us SqlUserStore) Save(user *model.User) StoreChannel {
|
||||
@@ -64,7 +65,7 @@ func (us SqlUserStore) Save(user *model.User) StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
if count, err := us.GetMaster().SelectInt("SELECT COUNT(0) FROM Users WHERE TeamId = ? AND DeleteAt = 0", user.TeamId); err != nil {
|
||||
if count, err := us.GetMaster().SelectInt("SELECT COUNT(0) FROM Users WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": user.TeamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.Save", "Failed to get current team member count", "teamId="+user.TeamId+", "+err.Error())
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
@@ -156,7 +157,7 @@ func (us SqlUserStore) UpdateLastPingAt(userId string, time int64) StoreChannel
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET LastPingAt = ? WHERE Id = ?", time, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET LastPingAt = :LastPingAt WHERE Id = :UserId", map[string]interface{}{"LastPingAt": time, "UserId": userId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.UpdateLastPingAt", "We couldn't update the last_ping_at", "user_id="+userId)
|
||||
} else {
|
||||
result.Data = userId
|
||||
@@ -175,7 +176,7 @@ func (us SqlUserStore) UpdateLastActivityAt(userId string, time int64) StoreChan
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET LastActivityAt = ? WHERE Id = ?", time, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET LastActivityAt = :LastActivityAt WHERE Id = :UserId", map[string]interface{}{"LastActivityAt": time, "UserId": userId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.UpdateLastActivityAt", "We couldn't update the last_activity_at", "user_id="+userId)
|
||||
} else {
|
||||
result.Data = userId
|
||||
@@ -194,7 +195,7 @@ func (us SqlUserStore) UpdateUserAndSessionActivity(userId string, sessionId str
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
if _, err := us.GetMaster().Exec("UPDATE Sessions, Users SET Users.LastActivityAt = ?, Sessions.LastActivityAt = ? WHERE Users.Id = ? AND Sessions.Id = ?", time, time, userId, sessionId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Sessions, Users SET Users.LastActivityAt = :UserLastActivityAt, Sessions.LastActivityAt = :SessionLastActivityAt WHERE Users.Id = :UserId AND Sessions.Id = :SessionId", map[string]interface{}{"UserLastActivityAt": time, "SessionLastActivityAt": time, "UserId": userId, "SessionId": sessionId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.UpdateLastActivityAt", "We couldn't update the last_activity_at", "user_id="+userId+" session_id="+sessionId+" err="+err.Error())
|
||||
} else {
|
||||
result.Data = userId
|
||||
@@ -216,7 +217,7 @@ func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) StoreChanne
|
||||
|
||||
updateAt := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET Password = ?, LastPasswordUpdate = ?, UpdateAt = ? WHERE Id = ?", hashedPassword, updateAt, updateAt, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET Password = :Password, LastPasswordUpdate = :LastPasswordUpdate, UpdateAt = :UpdateAt WHERE Id = :UserId", map[string]interface{}{"Password": hashedPassword, "LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.UpdatePassword", "We couldn't update the user password", "id="+userId+", "+err.Error())
|
||||
} else {
|
||||
result.Data = userId
|
||||
@@ -258,7 +259,7 @@ func (s SqlUserStore) GetEtagForProfiles(teamId string) StoreChannel {
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
updateAt, err := s.GetReplica().SelectInt("SELECT UpdateAt FROM Users WHERE TeamId = ? ORDER BY UpdateAt DESC LIMIT 1", teamId)
|
||||
updateAt, err := s.GetReplica().SelectInt("SELECT UpdateAt FROM Users WHERE TeamId = :TeamId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"TeamId": teamId})
|
||||
if err != nil {
|
||||
result.Data = fmt.Sprintf("%v.%v", model.ETAG_ROOT_VERSION, model.GetMillis())
|
||||
} else {
|
||||
@@ -281,7 +282,7 @@ func (us SqlUserStore) GetProfiles(teamId string) StoreChannel {
|
||||
|
||||
var users []*model.User
|
||||
|
||||
if _, err := us.GetReplica().Select(&users, "SELECT * FROM Users WHERE TeamId = ?", teamId); err != nil {
|
||||
if _, err := us.GetReplica().Select(&users, "SELECT * FROM Users WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetProfiles", "We encounted an error while finding user profiles", err.Error())
|
||||
} else {
|
||||
|
||||
@@ -312,7 +313,7 @@ func (us SqlUserStore) GetByEmail(teamId string, email string) StoreChannel {
|
||||
|
||||
user := model.User{}
|
||||
|
||||
if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId=? AND Email=?", teamId, email); err != nil {
|
||||
if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId = :TeamId AND Email = :Email", map[string]interface{}{"TeamId": teamId, "Email": email}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetByEmail", "We couldn't find the existing account", "teamId="+teamId+", email="+email+", "+err.Error())
|
||||
}
|
||||
|
||||
@@ -334,7 +335,7 @@ func (us SqlUserStore) GetByUsername(teamId string, username string) StoreChanne
|
||||
|
||||
user := model.User{}
|
||||
|
||||
if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId=? AND Username=?", teamId, username); err != nil {
|
||||
if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId = :TeamId AND Username = :Username", map[string]interface{}{"TeamId": teamId, "Username": username}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetByUsername", "We couldn't find the existing account", "teamId="+teamId+", username="+username+", "+err.Error())
|
||||
}
|
||||
|
||||
@@ -353,7 +354,7 @@ func (us SqlUserStore) VerifyEmail(userId string) StoreChannel {
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET EmailVerified = 1 WHERE Id = ?", userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET EmailVerified = 1 WHERE Id = :UserId", map[string]interface{}{"UserId": userId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.VerifyEmail", "Unable to update verify email field", "userId="+userId+", "+err.Error())
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user