Fixing merges for latest postgres
Этот коммит содержится в:
@@ -35,8 +35,8 @@
|
|||||||
},
|
},
|
||||||
"SqlSettings": {
|
"SqlSettings": {
|
||||||
"DriverName": "mysql",
|
"DriverName": "mysql",
|
||||||
"DataSource": "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test",
|
"DataSource": "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8",
|
||||||
"DataSourceReplicas": ["mmuser:mostest@tcp(dockerhost:3306)/mattermost_test"],
|
"DataSourceReplicas": ["mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8"],
|
||||||
"MaxIdleConns": 10,
|
"MaxIdleConns": 10,
|
||||||
"MaxOpenConns": 10,
|
"MaxOpenConns": 10,
|
||||||
"Trace": false,
|
"Trace": false,
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
},
|
},
|
||||||
"SqlSettings": {
|
"SqlSettings": {
|
||||||
"DriverName": "mysql",
|
"DriverName": "mysql",
|
||||||
"DataSource": "mmuser:mostest@tcp(localhost:3306)/mattermost_test",
|
"DataSource": "mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4,utf8",
|
||||||
"DataSourceReplicas": ["mmuser:mostest@tcp(localhost:3306)/mattermost_test"],
|
"DataSourceReplicas": ["mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4,utf8"],
|
||||||
"MaxIdleConns": 10,
|
"MaxIdleConns": 10,
|
||||||
"MaxOpenConns": 10,
|
"MaxOpenConns": 10,
|
||||||
"Trace": false,
|
"Trace": false,
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func (s SqlChannelStore) Save(channel *model.Channel) StoreChannel {
|
|||||||
if err := s.GetMaster().Insert(channel); err != nil {
|
if err := s.GetMaster().Insert(channel); err != nil {
|
||||||
if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") {
|
if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") {
|
||||||
dupChannel := model.Channel{}
|
dupChannel := model.Channel{}
|
||||||
s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId=? AND Name=? AND DeleteAt > 0", channel.TeamId, channel.Name)
|
s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
|
||||||
if dupChannel.DeleteAt > 0 {
|
if dupChannel.DeleteAt > 0 {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name was previously created", "id="+channel.Id+", "+err.Error())
|
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name was previously created", "id="+channel.Id+", "+err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -83,14 +83,7 @@ func NewSqlStore() Store {
|
|||||||
|
|
||||||
func setupConnection(con_type string, driver string, dataSource string, maxIdle int, maxOpen int, trace bool) *gorp.DbMap {
|
func setupConnection(con_type string, driver string, dataSource string, maxIdle int, maxOpen int, trace bool) *gorp.DbMap {
|
||||||
|
|
||||||
charset := ""
|
db, err := dbsql.Open(driver, dataSource)
|
||||||
if strings.Index(dataSource, "?") > -1 {
|
|
||||||
charset = "&charset=utf8mb4,utf8"
|
|
||||||
} else {
|
|
||||||
charset = "?charset=utf8mb4,utf8"
|
|
||||||
}
|
|
||||||
|
|
||||||
db, err := dbsql.Open(driver, dataSource+charset)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l4g.Critical("Failed to open sql connection to '%v' err:%v", dataSource, err)
|
l4g.Critical("Failed to open sql connection to '%v' err:%v", dataSource, err)
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
@@ -130,6 +123,11 @@ func setupConnection(con_type string, driver string, dataSource string, maxIdle
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||||
|
// XXX TODO FIXME this should be removed after 0.6.0
|
||||||
|
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
count, err := ss.GetMaster().SelectInt(
|
count, err := ss.GetMaster().SelectInt(
|
||||||
`SELECT
|
`SELECT
|
||||||
COUNT(0) AS column_exists
|
COUNT(0) AS column_exists
|
||||||
@@ -152,6 +150,12 @@ func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool {
|
func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool {
|
||||||
|
|
||||||
|
// XXX TODO FIXME this should be removed after 0.6.0
|
||||||
|
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if ss.DoesColumnExist(tableName, columnName) {
|
if ss.DoesColumnExist(tableName, columnName) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -167,6 +171,12 @@ func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ss SqlStore) RemoveColumnIfExists(tableName string, columnName string) bool {
|
func (ss SqlStore) RemoveColumnIfExists(tableName string, columnName string) bool {
|
||||||
|
|
||||||
|
// XXX TODO FIXME this should be removed after 0.6.0
|
||||||
|
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if !ss.DoesColumnExist(tableName, columnName) {
|
if !ss.DoesColumnExist(tableName, columnName) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -182,15 +192,18 @@ func (ss SqlStore) RemoveColumnIfExists(tableName string, columnName string) boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ss SqlStore) RenameColumnIfExists(tableName string, oldColumnName string, newColumnName string, colType string) bool {
|
func (ss SqlStore) RenameColumnIfExists(tableName string, oldColumnName string, newColumnName string, colType string) bool {
|
||||||
|
|
||||||
|
// XXX TODO FIXME this should be removed after 0.6.0
|
||||||
|
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if !ss.DoesColumnExist(tableName, oldColumnName) {
|
if !ss.DoesColumnExist(tableName, oldColumnName) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " CHANGE " + oldColumnName + " " + newColumnName + " " + colType)
|
_, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " CHANGE " + oldColumnName + " " + newColumnName + " " + colType)
|
||||||
|
|
||||||
// when we eventually support PostgreSQL, we can use the following instead
|
|
||||||
//_, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " RENAME COLUMN " + oldColumnName + " TO " + newColumnName)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l4g.Critical("Failed to rename column %v", err)
|
l4g.Critical("Failed to rename column %v", err)
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
@@ -209,27 +222,55 @@ func (ss SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, fullText bool) {
|
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 {
|
if utils.Cfg.SqlSettings.DriverName == "postgres" {
|
||||||
l4g.Critical("Failed to check index", err)
|
_, 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)
|
time.Sleep(time.Second)
|
||||||
panic("Failed to check index" + err.Error())
|
panic("Failed to create index because of missing driver")
|
||||||
}
|
|
||||||
|
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := s.GetMaster().Insert(team); err != nil {
|
if err := s.GetMaster().Insert(team); err != nil {
|
||||||
if IsUniqueConstraintError(err.Error(), "Name", "teams_domain_key") {
|
if IsUniqueConstraintError(err.Error(), "Name", "teams_name_key") {
|
||||||
result.Err = model.NewAppError("SqlTeamStore.Save", "A team with that domain already exists", "id="+team.Id+", "+err.Error())
|
result.Err = model.NewAppError("SqlTeamStore.Save", "A team with that domain already exists", "id="+team.Id+", "+err.Error())
|
||||||
} else {
|
} else {
|
||||||
result.Err = model.NewAppError("SqlTeamStore.Save", "We couldn't save the team", "id="+team.Id+", "+err.Error())
|
result.Err = model.NewAppError("SqlTeamStore.Save", "We couldn't save the team", "id="+team.Id+", "+err.Error())
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ func (us SqlUserStore) GetByAuth(teamId string, authData string, authService str
|
|||||||
|
|
||||||
user := model.User{}
|
user := model.User{}
|
||||||
|
|
||||||
if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId=? AND AuthData=? AND AuthService=?", teamId, authData, authService); err != nil {
|
if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId = :TeamId AND AuthData = :AuthData AND AuthService = :AuthService", map[string]interface{}{"TeamId": teamId, "AuthData": authData, "AuthService": authService}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlUserStore.GetByAuth", "We couldn't find the existing account", "teamId="+teamId+", authData="+authData+", authService="+authService+", "+err.Error())
|
result.Err = model.NewAppError("SqlUserStore.GetByAuth", "We couldn't find the existing account", "teamId="+teamId+", authData="+authData+", authService="+authService+", "+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user