Remove code duplication and move utility methods to the store utils (#20091)

* Remove code duplication and move utility methods to the store utils

* Fix typo
Этот коммит содержится в:
Miguel de la Cruz
2022-04-29 12:15:38 +02:00
коммит произвёл GitHub
родитель 79a0d3dac4
Коммит c076f9fdf9
6 изменённых файлов: 60 добавлений и 98 удалений

Просмотреть файл

@@ -12,6 +12,8 @@ import (
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
"github.com/go-sql-driver/mysql"
)
var escapeLikeSearchChar = []string{
@@ -170,3 +172,28 @@ func DSNHasBinaryParam(dsn string) (bool, error) {
func AppendBinaryFlag(buf []byte) []byte {
return append([]byte{0x01}, buf...)
}
// AppendMultipleStatementsFlag attached dsn parameters to MySQL dsn in order to make migrations work.
func AppendMultipleStatementsFlag(dataSource string) (string, error) {
config, err := mysql.ParseDSN(dataSource)
if err != nil {
return "", err
}
if config.Params == nil {
config.Params = map[string]string{}
}
config.Params["multiStatements"] = "true"
return config.FormatDSN(), nil
}
// ResetReadTimeout removes the timeout constraint from the MySQL dsn.
func ResetReadTimeout(dataSource string) (string, error) {
config, err := mysql.ParseDSN(dataSource)
if err != nil {
return "", err
}
config.ReadTimeout = 0
return config.FormatDSN(), nil
}