Skip to content

Commit

Permalink
Adds a check that errors on store start if MariaDB is detected (matte…
Browse files Browse the repository at this point in the history
…rmost-community#3725)

* Adds a check that errors on store start if MariaDB is detected

* Fix linter

* Update error message

Co-authored-by: Mattermod <[email protected]>
  • Loading branch information
mgdelacroix and mattermod authored Aug 24, 2022
1 parent 2b39745 commit e1a39e5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/services/store/sqlstore/sqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package sqlstore

import (
"database/sql"
"errors"
"fmt"
"net/url"
"strings"

sq "github.com/Masterminds/squirrel"

Expand All @@ -15,6 +17,9 @@ import (
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)

//nolint:lll
var ErrInvalidMariaDB = errors.New("MariaDB database is not supported, you can find more information at https://docs.mattermost.com/install/software-hardware-requirements.html#database-software")

// SQLStore is a SQL database.
type SQLStore struct {
db *sql.DB
Expand Down Expand Up @@ -53,6 +58,10 @@ func New(params Params) (*SQLStore, error) {
servicesAPI: params.ServicesAPI,
}

if store.IsMariaDB() {
return nil, ErrInvalidMariaDB
}

var err error
store.isBinaryParam, err = store.computeBinaryParam()
if err != nil {
Expand All @@ -70,6 +79,22 @@ func New(params Params) (*SQLStore, error) {
return store, nil
}

func (s *SQLStore) IsMariaDB() bool {
if s.dbType != model.MysqlDBType {
return false
}

row := s.db.QueryRow("SELECT Version()")

var version string
if err := row.Scan(&version); err != nil {
s.logger.Error("error checking database version", mlog.Err(err))
return false
}

return strings.Contains(strings.ToLower(version), "mariadb")
}

// computeBinaryParam returns whether the data source uses binary_parameters
// when using Postgres.
func (s *SQLStore) computeBinaryParam() (bool, error) {
Expand Down

0 comments on commit e1a39e5

Please sign in to comment.