github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/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 kuser mattermost_test'
     8  
     9  echo "Importing postgres dump from version 5.0"
    10  docker exec -i mattermost-postgres psql -U kuser -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://kuser:mostest@localhost: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://kuser:mostest@localhost: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 kuser > $DUMPDIR/migrated.sql
    27  docker exec mattermost-postgres pg_dump --schema-only -d latest -U kuser > $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 kuser 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
    37      echo "Both schemas are same"
    38  else
    39      echo "Schema mismatch"
    40      cat $DUMPDIR/diff.txt
    41  fi
    42  rm -rf $TMPDIR $DUMPDIR
    43  
    44  exit $diffErrorCode