#!/usr/bin/env bash compose_file="schema-test-docker-compose.yml" config_file="schema-test-source-config.json" connect_log="connect.log" records_file="records.json" function compose(){ sudo docker-compose -f ${compose_file} $* } function clean(){ echo "Shutting down services" compose down -v echo "Deleting files" rm ${compose_file} ${config_file} ${connect_log} ${records_file} } if [[ ${1} = 'clean' ]]; then clean exit 0 fi if [[ -z "$(which jq)" ]]; then echo "You'll need jq installed, see https://stedolan.github.io/jq/download/" exit 1 fi if [[ -z "$(which docker-compose)" ]]; then echo "You'll need docker-compose (and docker) installed, see https://docs.docker.com/compose/install/" exit 1 fi echo "creating ${config_file}" tee ./${config_file} </dev/null 2>/dev/null & echo "Wait for kafka to be up (mysql will be long ready by then)" wait_attempts=300 until (curl -s "http://localhost:8082/topics" >/dev/null); do sleep 0.1s wait_attempts="$((wait_attempts - 1))" if [[ "${wait_attempts}" = "0" ]]; then echo "timeout during waiting for kafka!" exit 1 fi done echo "Create table in database" ( mysql -u root -proot -h 127.0.0.1 -P 3306 < ${records_file} || exit cat ${records_file} | jq -c '.[].value.after["test_db.test.schema_test.Value"]' echo "Creating additional table" ( mysql -u root -proot -h 127.0.0.1 -P 3306 <> ${records_file} || exit cat ${records_file} | jq -c '.[].value.after["test_db.test.schema_test.Value"]' echo "Show schema" curl -s localhost:8081/subjects/cdc-data-test-schema_test-value/versions/latest | jq -r '.schema | fromjson | .fields[] | select( .name == "before") | .type[1].fields' || exit echo "select data from mysql" mysql -u root -proot -h 127.0.0.1 -P 3306 test -e "select * from schema_test" echo "dumping connect log at ${connect_log}, records are at ${records_file}" compose logs connect >> ${connect_log} printf "remove files and shut down? (yN): " read ans if [[ "$ans" = "y" || "$ans" = "Y" ]]; then clean exit 0 fi echo "You can run test_add_columns_after.sh clean to clean up afterwards"