Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Aug 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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