github.com/rifflearning/mattermost-server@v5.11.1+incompatible/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 mmuser; GRANT ALL PRIVILEGES ON latest.* TO mmuser"
     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 'mmuser:mostest@tcp(dockerhost: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 'mmuser:mostest@tcp(dockerhost: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 "Generating dump"
    26  docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest migrated > $DUMPDIR/migrated.sql
    27  docker exec mattermost-mysql mysqldump --skip-opt --no-data --compact -u root -pmostest latest > $DUMPDIR/latest.sql
    28  
    29  echo "Removing databases created for db comparison"
    30  docker exec mattermost-mysql mysql -uroot -pmostest -e "DROP DATABASE migrated; DROP DATABASE latest"
    31  
    32  echo "Generating diff"
    33  diff $DUMPDIR/migrated.sql $DUMPDIR/latest.sql > $DUMPDIR/diff.txt
    34  diffErrorCode=$?
    35  
    36  if [ $diffErrorCode -eq 0 ]; then echo "Both schemas are same";else cat $DUMPDIR/diff.txt; fi
    37  rm -rf $TMPDIR $DUMPDIR
    38  
    39  exit $diffErrorCode