Skip to content

Commit

Permalink
Bump up the minimum required MySQL version (mattermost#25465)
Browse files Browse the repository at this point in the history
MySQL 5.7 is at end of life.

https://mattermost.atlassian.net/browse/MM-55589

```release-note
We bump up minimum MySQL version to be 8.0.0
```


Co-authored-by: Mattermost Build <[email protected]>
Co-authored-by: Ibrahim Serdar Acikgoz <[email protected]>
  • Loading branch information
3 people authored Jan 11, 2024
1 parent 4ab6b98 commit 04cf1ed
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/esrupgrade-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
--ulimit nofile=8096:8096 \
--env-file=dotenv/test.env \
--env MM_SQLSETTINGS_DRIVERNAME="mysql" \
--env MM_SQLSETTINGS_DATASOURCE="mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&multiStatements=true&maxAllowedPacket=4194304" \
--env MM_SQLSETTINGS_DATASOURCE="mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4&multiStatements=true&maxAllowedPacket=4194304" \
-v ~/work/mattermost:/mm \
-w /mm \
$BUILD_IMAGE &
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
env:
COMPOSE_PROJECT_NAME: ghactions
BUILD_IMAGE: mattermost/mattermost-build-server:20230904_golang-1.20.7
TEST_IMAGE: migration-test-image
defaults:
run:
working-directory: server
Expand All @@ -20,6 +21,23 @@ jobs:
docker compose --ansi never run --rm start_dependencies
docker compose --ansi never exec -T minio sh -c 'mkdir -p /data/mattermost-test';
docker compose --ansi never ps
- name: Fix MySQL user permissions
run: |
cd build
docker exec ${COMPOSE_PROJECT_NAME}-mysql-1 sh -c "sed -i '/# default-authentication-plugin/c\default-authentication-plugin=mysql_native_password' /etc/my.cnf"
docker exec ${COMPOSE_PROJECT_NAME}-mysql-1 sh -c "mysql -u root -pmostest -e \"ALTER USER 'mmuser'@'%' IDENTIFIED WITH mysql_native_password BY 'mostest';\""
docker exec ${COMPOSE_PROJECT_NAME}-mysql-1 sh -c "mysql -u root -pmostest -e \"ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'mostest';\""
docker restart ${COMPOSE_PROJECT_NAME}-mysql-1 && sleep 10
- name: Build test image
run: |
echo -e "FROM $BUILD_IMAGE\n\nRUN apt update && \
apt remove -y pgloader && \
apt install -y sbcl unzip libsqlite3-dev make curl gawk freetds-dev libzip-dev && \
git clone https://github.com/dimitri/pgloader.git && \
cd pgloader && \
make && \
mv build/bin/pgloader /bin" >> dockerfile_tmp
docker build -t $TEST_IMAGE - < dockerfile_tmp
- name: Generate test-data
run: |
docker run --net ${COMPOSE_PROJECT_NAME}_mm-test \
Expand All @@ -29,7 +47,7 @@ jobs:
-e GOCACHE=/go/cache \
-v $PWD:/mattermost \
-w /mattermost \
$BUILD_IMAGE \
$TEST_IMAGE \
make test-data
- name: Migrate the DB and compare
run: |
Expand All @@ -40,7 +58,7 @@ jobs:
-e GOCACHE=/go/cache \
-v $PWD:/mattermost \
-w /mattermost \
$BUILD_IMAGE \
$TEST_IMAGE \
make test-migration
- name: Upload artifacts
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server-ci-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ jobs:
uses: ./.github/workflows/server-test-template.yml
with:
name: MySQL
datasource: mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&multiStatements=true&maxAllowedPacket=4194304
datasource: mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4&multiStatements=true&maxAllowedPacket=4194304
drivername: mysql
logsartifact: mysql-server-test-logs
secrets: inherit
Expand Down
2 changes: 1 addition & 1 deletion server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ test-migration:
@sed -i'' -e 's|{{ .source_schema }}|${MYSQL_SCHEMA}|g' tests/temp.load

# run pgloader and save the logs
pgloader tests/temp.load > migration.log
pgloader --debug tests/temp.load > migration.log

$(GO) install github.com/mattermost/dbcmp/cmd/dbcmp@latest
# compare two database contents
Expand Down
4 changes: 2 additions & 2 deletions server/build/docker-compose.common.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '2.4'
services:
mysql:
image: "mysql/mysql-server:5.7.12"
image: "mysql/mysql-server:8.0.32"
restart: always
networks:
- mm-test
Expand All @@ -19,7 +19,7 @@ services:
volumes:
- ./docker/mysql.conf.d/source.cnf:/etc/mysql/conf.d/mysql.cnf
mysql-read-replica:
image: "mysql/mysql-server:5.7.12"
image: "mysql/mysql-server:8.0.32"
restart: always
networks:
- mm-test
Expand Down
1 change: 1 addition & 0 deletions server/build/docker/mysql.conf.d/custom.cnf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[mysqld]
bind-address = 0.0.0.0

default-authentication-plugin=mysql_native_password
log-output = NONE
slow-query-log = 0
innodb_flush_log_at_trx_commit = 2
Expand Down
4 changes: 2 additions & 2 deletions server/build/dotenv/migration.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ MYSQL_USERNAME=root
MYSQL_PASSWORD=mostest
MYSQL_SCHEMA=mattermost_test
POSTGRES_MIGRATIONS_PATH=./channels/db/migrations/postgres
MYSQL_DSN=${MYSQL_USERNAME}:${MYSQL_PASSWORD}@tcp(mysql:3306)/${MYSQL_SCHEMA}?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s&multiStatements=true
MYSQL_DSN=${MYSQL_USERNAME}:${MYSQL_PASSWORD}@tcp(mysql:3306)/${MYSQL_SCHEMA}?charset=utf8mb4&readTimeout=30s&writeTimeout=30s&multiStatements=true
POSTGRES_DSN=postgres://${PG_USERNAME}:${PG_PASSWORD}@postgres:5432/${PG_SCHEMA}?sslmode=disable

MM_SERVICESETTINGS_ENABLELOCALMODE=true
MM_SQLSETTINGS_DRIVERNAME=mysql
MM_SQLSETTINGS_DATASOURCE=mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s&multiStatements=true&maxAllowedPacket=4194304
MM_SQLSETTINGS_DATASOURCE=mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4&readTimeout=30s&writeTimeout=30s&multiStatements=true&maxAllowedPacket=4194304
MAX_WAIT_SECONDS=500
IS_CI=true
2 changes: 1 addition & 1 deletion server/build/dotenv/test.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TEST_DATABASE_MYSQL_DSN=mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s&multiStatements=true&maxAllowedPacket=4194304
TEST_DATABASE_MYSQL_DSN=mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4&readTimeout=30s&writeTimeout=30s&multiStatements=true&maxAllowedPacket=4194304
TEST_DATABASE_POSTGRESQL_DSN=postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10
TEST_DATABASE_MYSQL_ROOT_PASSWD=mostest
GOBIN=/mattermost/server/bin
Expand Down
2 changes: 1 addition & 1 deletion server/build/gitlab-dc.mysql.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '2.4'
services:
mysql:
image: mattermostdevelopment/mirrored-mysql:5.7.12
image: mattermostdevelopment/mirrored-mysql:8.0.32
restart: always
environment:
MYSQL_ROOT_HOST: "%"
Expand Down
2 changes: 1 addition & 1 deletion server/build/gitlab-dc.schemamysql.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '2.4'
services:
mysql:
image: mattermostdevelopment/mirrored-mysql:5.7.12
image: mattermostdevelopment/mirrored-mysql:8.0.32
restart: always
environment:
MYSQL_ROOT_HOST: "%"
Expand Down
6 changes: 1 addition & 5 deletions server/channels/store/sqlstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ const (
// 9.6.3 would be 90603.
minimumRequiredPostgresVersion = 110000
// major*1000 + minor*100 + patch
minimumRequiredMySQLVersion = 5712
minimumRecommendedMySQLVersion = 8000
minimumRequiredMySQLVersion = 8000

migrationsDirectionUp migrationDirection = "up"
migrationsDirectionDown migrationDirection = "down"
Expand Down Expand Up @@ -1232,9 +1231,6 @@ func (ss *SqlStore) ensureMinimumDBVersion(ver string) (bool, error) {
return false, fmt.Errorf("cannot parse MySQL DB version: %w", err2)
}
intVer := majorVer*1000 + minorVer*100 + patchVer
if intVer < minimumRecommendedMySQLVersion {
mlog.Warn("The MySQL version being used is EOL. Please upgrade to a later version.", mlog.Int("current_version", intVer), mlog.Int("minimum_recommended_version", minimumRecommendedMySQLVersion))
}
if intVer < minimumRequiredMySQLVersion {
return false, fmt.Errorf("Minimum MySQL version requirements not met. Found: %s, Wanted: %s", versionString(intVer, *ss.settings.DriverName), versionString(minimumRequiredMySQLVersion, *ss.settings.DriverName))
}
Expand Down
4 changes: 2 additions & 2 deletions server/channels/store/storetest/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
)

const (
defaultMysqlDSN = "mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s&multiStatements=true&maxAllowedPacket=4194304"
defaultMysqlDSN = "mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4&readTimeout=30s&writeTimeout=30s&multiStatements=true&maxAllowedPacket=4194304"
defaultPostgresqlDSN = "postgres://mmuser:mostest@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10"
defaultMysqlRootPWD = "mostest"
defaultMysqlReplicaDSN = "root:mostest@tcp(localhost:3307)/mattermost_test?charset=utf8mb4,utf8\u0026readTimeout=30s"
defaultMysqlReplicaDSN = "root:mostest@tcp(localhost:3307)/mattermost_test?charset=utf8mb4\u0026readTimeout=30s"
)

func getEnv(name, defaultValue string) string {
Expand Down
4 changes: 2 additions & 2 deletions server/scripts/mysql-migration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ docker exec -i mattermost-mysql mysql -D migrated -uroot -pmostest -e "INSERT IN

echo "Setting up config for db migration"
cat config/config.json | \
jq '.SqlSettings.DataSource = "mmuser:mostest@tcp(localhost:3306)/migrated?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"' | \
jq '.SqlSettings.DataSource = "mmuser:mostest@tcp(localhost:3306)/migrated?charset=utf8mb4&readTimeout=30s&writeTimeout=30s"' | \
jq '.SqlSettings.DriverName = "mysql"' > $TMPDIR/config.json

echo "Running the migration"
make ARGS="db migrate --config $TMPDIR/config.json" run-cli

echo "Setting up config for fresh db setup"
cat config/config.json | \
jq '.SqlSettings.DataSource = "mmuser:mostest@tcp(localhost:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"' | \
jq '.SqlSettings.DataSource = "mmuser:mostest@tcp(localhost:3306)/latest?charset=utf8mb4&readTimeout=30s&writeTimeout=30s"' | \
jq '.SqlSettings.DriverName = "mysql"' > $TMPDIR/config.json

echo "Setting up fresh db"
Expand Down
2 changes: 1 addition & 1 deletion server/tests/test-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
"SqlSettings": {
"DriverName": "mysql",
"DataSource": "mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s\u0026maxAllowedPacket=4194304",
"DataSource": "mmuser:mostest@tcp(localhost:3306)/mattermost_test?charset=utf8mb4\u0026readTimeout=30s\u0026writeTimeout=30s\u0026maxAllowedPacket=4194304",
"DataSourceReplicas": [],
"DataSourceSearchReplicas": [],
"MaxIdleConns": 20,
Expand Down

0 comments on commit 04cf1ed

Please sign in to comment.