mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-13341] Add an upgrade test to verify schema (#10419)
* [MM-13341] Add an upgrade test to verify schema Upgrade test is done by following steps: 1. A mysql dump generated from v4.10.0 is imported in a database and is ran through migration code 2. Another fresh database is generated without any initial data, which gets latest schema. 3. Diff between these 2 databases is generated using mysqldiff tool from mysql utilities For db setup, version cli command is used which takes care of migration or setup of fresh db * Using 5.7 tag for mysql docker image which is already used for db setup * Starting docker containers for db before running tests * Using db from v5.0.0 for migration test * Added migration test for psql and made some improvements in running commands in docker * Add postgres db dump file * Updated message * moved dump files to scripts and using error code from diff command
This commit is contained in:
committed by
Jesse Hallam
parent
498b988a6b
commit
a9c327c068
4
Makefile
4
Makefile
@@ -397,6 +397,10 @@ test-compile:
|
||||
$(GO) test $(GOFLAGS) -c $$package; \
|
||||
done
|
||||
|
||||
test-db-migration: start-docker
|
||||
./scripts/mysql-migration-test.sh
|
||||
./scripts/psql-migration-test.sh
|
||||
|
||||
test-server: start-docker go-junit-report do-cover-file ## Runs tests.
|
||||
ifeq ($(BUILD_ENTERPRISE_READY),true)
|
||||
@echo Running all tests
|
||||
|
||||
1054
scripts/mattermost-mysql-5.0.sql
Normal file
1054
scripts/mattermost-mysql-5.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
1816
scripts/mattermost-postgresql-5.0.sql
Normal file
1816
scripts/mattermost-postgresql-5.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
39
scripts/mysql-migration-test.sh
Executable file
39
scripts/mysql-migration-test.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
TMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmpConfigDir'`
|
||||
DUMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'dumpDir'`
|
||||
|
||||
cp config/config.json $TMPDIR
|
||||
|
||||
echo "Creating databases"
|
||||
docker exec mattermost-mysql mysql -uroot -pmostest -e "CREATE DATABASE migrated; CREATE DATABASE latest; GRANT ALL PRIVILEGES ON migrated.* TO mmuser; GRANT ALL PRIVILEGES ON latest.* TO mmuser"
|
||||
|
||||
echo "Importing mysql dump from version 5.0"
|
||||
docker exec -i mattermost-mysql mysql -D migrated -uroot -pmostest < $(pwd)/scripts/mattermost-mysql-5.0.sql
|
||||
|
||||
echo "Setting up config for db migration"
|
||||
make ARGS="config set SqlSettings.DataSource 'mmuser:mostest@tcp(dockerhost:3306)/migrated?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' --config $TMPDIR/config.json" run-cli
|
||||
make ARGS="config set SqlSettings.DriverName 'mysql' --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Running the migration"
|
||||
make ARGS="version --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Setting up config for fresh db setup"
|
||||
make ARGS="config set SqlSettings.DataSource 'mmuser:mostest@tcp(dockerhost:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Setting up fresh db"
|
||||
make ARGS="version --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Generating dump"
|
||||
docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest migrated > $DUMPDIR/migrated.sql
|
||||
docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest latest > $DUMPDIR/latest.sql
|
||||
|
||||
echo "Removing databases created for db comparison"
|
||||
docker exec mattermost-mysql mysql -uroot -pmostest -e "DROP DATABASE migrated; DROP DATABASE latest"
|
||||
|
||||
echo "Generating diff"
|
||||
diff $DUMPDIR/migrated.sql $DUMPDIR/latest.sql > $DUMPDIR/diff.txt
|
||||
diffErrorCode=$?
|
||||
|
||||
if [ $diffErrorCode -eq 0 ]; then echo "Both schemas are same";else cat $DUMPDIR/diff.txt; fi
|
||||
rm -rf $TMPDIR $DUMPDIR
|
||||
|
||||
exit $diffErrorCode
|
||||
39
scripts/psql-migration-test.sh
Executable file
39
scripts/psql-migration-test.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
TMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmpConfigDir'`
|
||||
DUMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'dumpDir'`
|
||||
|
||||
cp config/config.json $TMPDIR
|
||||
|
||||
echo "Creating databases"
|
||||
docker exec mattermost-postgres sh -c 'exec echo "CREATE DATABASE migrated; CREATE DATABASE latest;" | exec psql -U mmuser mattermost_test'
|
||||
|
||||
echo "Importing postgres dump from version 5.0"
|
||||
docker exec -i mattermost-postgres psql -U mmuser -d migrated < $(pwd)/scripts/mattermost-postgresql-5.0.sql
|
||||
|
||||
echo "Setting up config for db migration"
|
||||
make ARGS="config set SqlSettings.DataSource 'postgres://mmuser:mostest@dockerhost:5432/migrated?sslmode=disable&connect_timeout=10' --config $TMPDIR/config.json" run-cli
|
||||
make ARGS="config set SqlSettings.DriverName 'postgres' --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Running the migration"
|
||||
make ARGS="version --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Setting up config for fresh db setup"
|
||||
make ARGS="config set SqlSettings.DataSource 'postgres://mmuser:mostest@dockerhost:5432/latest?sslmode=disable&connect_timeout=10' --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Setting up fresh db"
|
||||
make ARGS="version --config $TMPDIR/config.json" run-cli
|
||||
|
||||
echo "Generating dump"
|
||||
docker exec mattermost-postgres pg_dump --schema-only -d migrated -U mmuser > $DUMPDIR/migrated.sql
|
||||
docker exec mattermost-postgres pg_dump --schema-only -d latest -U mmuser > $DUMPDIR/latest.sql
|
||||
|
||||
echo "Removing databases created for db comparison"
|
||||
docker exec mattermost-postgres sh -c 'exec echo "DROP DATABASE migrated; DROP DATABASE latest;" | exec psql -U mmuser mattermost_test'
|
||||
|
||||
echo "Generating diff"
|
||||
diff $DUMPDIR/migrated.sql $DUMPDIR/latest.sql > $DUMPDIR/diff.txt
|
||||
diffErrorCode=$?
|
||||
|
||||
if [ $diffErrorCode -eq 0 ]; then echo "Both schemas are same";else cat $DUMPDIR/diff.txt; fi
|
||||
rm -rf $TMPDIR $DUMPDIR
|
||||
|
||||
exit $diffErrorCode
|
||||
Reference in New Issue
Block a user