github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/scripts/mysql-migration-test.sh (about) 1 TMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmpConfigDir'` 2 DUMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'dumpDir'` 3 4 cp config/config.json $TMPDIR 5 6 echo "Creating databases" 7 docker exec mattermost-mysql mysql -uroot -pmostest -e "CREATE DATABASE migrated; CREATE DATABASE latest; GRANT ALL PRIVILEGES ON migrated.* TO kuser; GRANT ALL PRIVILEGES ON latest.* TO kuser" 8 9 echo "Importing mysql dump from version 5.0" 10 docker exec -i mattermost-mysql mysql -D migrated -uroot -pmostest < $(pwd)/scripts/mattermost-mysql-5.0.sql 11 12 echo "Setting up config for db migration" 13 make ARGS="config set SqlSettings.DataSource 'kuser:mostest@tcp(localhost:3306)/migrated?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' --config $TMPDIR/config.json" run-cli 14 make ARGS="config set SqlSettings.DriverName 'mysql' --config $TMPDIR/config.json" run-cli 15 16 echo "Running the migration" 17 make ARGS="version --config $TMPDIR/config.json" run-cli 18 19 echo "Setting up config for fresh db setup" 20 make ARGS="config set SqlSettings.DataSource 'kuser:mostest@tcp(localhost:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' --config $TMPDIR/config.json" run-cli 21 22 echo "Setting up fresh db" 23 make ARGS="version --config $TMPDIR/config.json" run-cli 24 25 echo "Ignoring known MySQL mismatch: ClassMembers.SchemeGuest" 26 docker exec mattermost-mysql mysql -D migrated -uroot -pmostest -e "ALTER TABLE ClassMembers DROP COLUMN SchemeGuest;" 27 docker exec mattermost-mysql mysql -D latest -uroot -pmostest -e "ALTER TABLE ClassMembers DROP COLUMN SchemeGuest;" 28 29 echo "Generating dump" 30 docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest migrated > $DUMPDIR/migrated.sql 31 docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest latest > $DUMPDIR/latest.sql 32 33 echo "Removing databases created for db comparison" 34 docker exec mattermost-mysql mysql -uroot -pmostest -e "DROP DATABASE migrated; DROP DATABASE latest" 35 36 echo "Generating diff" 37 diff $DUMPDIR/migrated.sql $DUMPDIR/latest.sql > $DUMPDIR/diff.txt 38 diffErrorCode=$? 39 40 if [ $diffErrorCode -eq 0 ]; then 41 echo "Both schemas are same" 42 else 43 echo "Schema mismatch" 44 cat $DUMPDIR/diff.txt 45 fi 46 rm -rf $TMPDIR $DUMPDIR 47 48 exit $diffErrorCode