psql-migration-test.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. TMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'tmpConfigDir'`
  2. DUMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'dumpDir'`
  3. cp config/config.json $TMPDIR
  4. echo "Creating databases"
  5. docker exec mattermost-postgres sh -c 'exec echo "CREATE DATABASE migrated; CREATE DATABASE latest;" | exec psql -U mmuser mattermost_test'
  6. echo "Importing postgres dump from version 5.0"
  7. docker exec -i mattermost-postgres psql -U mmuser -d migrated < $(pwd)/scripts/mattermost-postgresql-5.0.sql
  8. echo "Setting up config for db migration"
  9. make ARGS="config set SqlSettings.DataSource 'postgres://mmuser:mostest@localhost:5432/migrated?sslmode=disable&connect_timeout=10' --config $TMPDIR/config.json" run-cli
  10. make ARGS="config set SqlSettings.DriverName 'postgres' --config $TMPDIR/config.json" run-cli
  11. echo "Running the migration"
  12. make ARGS="version --config $TMPDIR/config.json" run-cli
  13. echo "Setting up config for fresh db setup"
  14. make ARGS="config set SqlSettings.DataSource 'postgres://mmuser:mostest@localhost:5432/latest?sslmode=disable&connect_timeout=10' --config $TMPDIR/config.json" run-cli
  15. echo "Setting up fresh db"
  16. make ARGS="version --config $TMPDIR/config.json" run-cli
  17. echo "Generating dump"
  18. docker exec mattermost-postgres pg_dump --schema-only -d migrated -U mmuser > $DUMPDIR/migrated.sql
  19. docker exec mattermost-postgres pg_dump --schema-only -d latest -U mmuser > $DUMPDIR/latest.sql
  20. echo "Removing databases created for db comparison"
  21. docker exec mattermost-postgres sh -c 'exec echo "DROP DATABASE migrated; DROP DATABASE latest;" | exec psql -U mmuser mattermost_test'
  22. echo "Generating diff"
  23. diff $DUMPDIR/migrated.sql $DUMPDIR/latest.sql > $DUMPDIR/diff.txt
  24. diffErrorCode=$?
  25. if [ $diffErrorCode -eq 0 ]; then
  26. echo "Both schemas are same"
  27. else
  28. echo "Schema mismatch"
  29. cat $DUMPDIR/diff.txt
  30. fi
  31. rm -rf $TMPDIR $DUMPDIR
  32. exit $diffErrorCode