summaryrefslogtreecommitdiffstats
path: root/store/sql_team_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/sql_team_store.go')
-rw-r--r--store/sql_team_store.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/store/sql_team_store.go b/store/sql_team_store.go
index 6e7fc1c1e..193d0a62c 100644
--- a/store/sql_team_store.go
+++ b/store/sql_team_store.go
@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
- "strings"
)
type SqlTeamStore struct {
@@ -32,6 +31,7 @@ func (s SqlTeamStore) UpgradeSchemaIfNeeded() {
}
func (s SqlTeamStore) CreateIndexesIfNotExists() {
+ s.CreateIndexIfNotExists("idx_teams_domain", "Teams", "Domain")
}
func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
@@ -56,7 +56,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
}
if err := s.GetMaster().Insert(team); err != nil {
- if strings.Contains(err.Error(), "Duplicate entry") && strings.Contains(err.Error(), "for key 'Domain'") {
+ if IsUniqueConstraintError(err.Error(), "Domain", "teams_domain_key") {
result.Err = model.NewAppError("SqlTeamStore.Save", "A team with that domain already exists", "id="+team.Id+", "+err.Error())
} else {
result.Err = model.NewAppError("SqlTeamStore.Save", "We couldn't save the team", "id="+team.Id+", "+err.Error())
@@ -119,7 +119,7 @@ func (s SqlTeamStore) UpdateName(name string, teamId string) StoreChannel {
go func() {
result := StoreResult{}
- if _, err := s.GetMaster().Exec("UPDATE Teams SET Name = ? WHERE Id = ?", name, teamId); err != nil {
+ if _, err := s.GetMaster().Exec("UPDATE Teams SET Name = :Name WHERE Id = :Id", map[string]interface{}{"Name": name, "Id": teamId}); err != nil {
result.Err = model.NewAppError("SqlTeamStore.UpdateName", "We couldn't update the team name", "team_id="+teamId)
} else {
result.Data = teamId
@@ -161,7 +161,7 @@ func (s SqlTeamStore) GetByDomain(domain string) StoreChannel {
team := model.Team{}
- if err := s.GetReplica().SelectOne(&team, "SELECT * FROM Teams WHERE Domain=?", domain); err != nil {
+ if err := s.GetReplica().SelectOne(&team, "SELECT * FROM Teams WHERE Domain = :Domain", map[string]interface{}{"Domain": domain}); err != nil {
result.Err = model.NewAppError("SqlTeamStore.GetByDomain", "We couldn't find the existing team", "domain="+domain+", "+err.Error())
}
@@ -181,7 +181,7 @@ func (s SqlTeamStore) GetTeamsForEmail(email string) StoreChannel {
result := StoreResult{}
var data []*model.Team
- if _, err := s.GetReplica().Select(&data, "SELECT Teams.* FROM Teams, Users WHERE Teams.Id = Users.TeamId AND Users.Email = ?", email); err != nil {
+ if _, err := s.GetReplica().Select(&data, "SELECT Teams.* FROM Teams, Users WHERE Teams.Id = Users.TeamId AND Users.Email = :Email", map[string]interface{}{"Email": email}); err != nil {
result.Err = model.NewAppError("SqlTeamStore.GetTeamsForEmail", "We encounted a problem when looking up teams", "email="+email+", "+err.Error())
}