From e1a39e57ffc0492ff4d202e51ebf4de8286ea1e4 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Wed, 24 Aug 2022 22:36:43 +0200 Subject: [PATCH] Adds a check that errors on store start if MariaDB is detected (#3725) * Adds a check that errors on store start if MariaDB is detected * Fix linter * Update error message Co-authored-by: Mattermod --- server/services/store/sqlstore/sqlstore.go | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/server/services/store/sqlstore/sqlstore.go b/server/services/store/sqlstore/sqlstore.go index b011cf1847a..d8ea1d6d9bf 100644 --- a/server/services/store/sqlstore/sqlstore.go +++ b/server/services/store/sqlstore/sqlstore.go @@ -2,8 +2,10 @@ package sqlstore import ( "database/sql" + "errors" "fmt" "net/url" + "strings" sq "github.com/Masterminds/squirrel" @@ -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 @@ -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 { @@ -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) {