github.com/larkox/mattermost-server@v5.11.1+incompatible/scripts/psql-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-postgres sh -c 'exec echo "CREATE DATABASE migrated; CREATE DATABASE latest;" | exec psql -U mmuser mattermost_test'
     8  
     9  echo "Importing postgres dump from version 5.0"
    10  docker exec -i mattermost-postgres psql -U mmuser -d migrated < $(pwd)/scripts/mattermost-postgresql-5.0.sql
    11  
    12  echo "Setting up config for db migration"
    13  make ARGS="config set SqlSettings.DataSource 'postgres://mmuser:mostest@dockerhost:5432/migrated?sslmode=disable&connect_timeout=10' --config $TMPDIR/config.json" run-cli
    14  make ARGS="config set SqlSettings.DriverName 'postgres' --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 'postgres://mmuser:mostest@dockerhost:5432/latest?sslmode=disable&connect_timeout=10' --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-postgres pg_dump --schema-only -d migrated -U mmuser > $DUMPDIR/migrated.sql
    27  docker exec mattermost-postgres pg_dump --schema-only -d latest -U mmuser > $DUMPDIR/latest.sql
    28  
    29  echo "Removing databases created for db comparison"
    30  docker exec mattermost-postgres sh -c 'exec echo "DROP DATABASE migrated; DROP DATABASE latest;" | exec psql -U mmuser mattermost_test'
    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