<commit_before>#!/bin/sh
set -e

stdout () {
cat >&1 <<-EOT
${1}
EOT
}

stderr () {
cat >&2 <<-EOT
${1}
EOT
}

exists () {
if [ -z ${1} ]; then
    # ----
    stderr "ERROR: you need to set ${2}"
    # ----

    exit 1
else
    # ----
    stdout "OK: ${2} set"
    # ----
fi
}


echo "     _ _     _ _             _ _ "
echo "    |   \   /   |           (_)_)"
echo "    | |\ \ / /| | __ _  __ _ _ _ _  __   __"
echo "    | | \ _ / | |/ _\` |/ _\` | | | '_  \\/ __|"
echo "    | |       | | (_| | (_| | | | | | |\\__ \\"
echo "    |_|       |_|\__,_|\__,_|_|_|_| |_||__ /"

# ----
stdout "Checking requirements..."
# ----

exists ${MYSQL_SOURCE_ADDRESS} "MYSQL_SOURCE_ADDRESS"
exists ${MYSQL_SOURCE_USER} "MYSQL_SOURCE_USER"
exists ${MYSQL_SOURCE_PASSWORD} "MYSQL_SOURCE_PASSWORD"
exists ${MYSQL_SOURCE_DATABASE} "MYSQL_SOURCE_DATABASE"
exists ${MYSQL_TARGET_ADDRESS} "MYSQL_TARGET_ADDRESS"
exists ${MYSQL_TARGET_USER} "MYSQL_TARGET_USER"
exists ${MYSQL_TARGET_PASSWORD} "MYSQL_TARGET_PASSWORD"
exists ${MYSQL_TARGET_DATABASE} "MYSQL_TARGET_DATABASE"

if [ -z ${MYSQL_SOURCE_PORT} ]; then
    # ----
    stdout "INFO: MYSQL_SOURCE_PORT not set, default 3306"
    # ----

    MYSQL_SOURCE_PORT=3306
fi

if [ -z ${MYSQL_TARGET_PORT} ]; then
    # ----
    stdout "INFO: MYSQL_TARGET_PORT not set, default 3306"
    # ----

    MYSQL_TARGET_PORT=3306
fi

# ----
stdout "Successfully checked requirements!"
# ----

# ----
stdout "Begin transaction $(date)"
# ----

mysqldump -v --user="${MYSQL_SOURCE_USER}" --password="${<PASSWORD>}" --host="${MYSQL_SOURCE_ADDRESS}" --port="${MYSQL_SOURCE_PORT}" --routines --triggers "${MYSQL_SOURCE_DATABASE}" | sed -e 's/DEFINER=[^*]*\*/\*/' | mysql -v --user="${MYSQL_TARGET_USER}" --password="${<PASSWORD>}" --host="${MYSQL_TARGET_ADDRESS}" --port="${MYSQL_TARGET_PORT}" "${MYSQL_TARGET_DATABASE}"


if [ -e /sql/source.sql ]; then
    # ----
    stdout "Execute script on source"
    # ----
<commit_msg>Added support for docker volumes<commit_after>#!/bin/sh
set -e

stdout () {
cat >&1 <<-EOT
${1}
EOT
}

stderr () {
cat >&2 <<-EOT
${1}
EOT
}

exists () {
if [ -z ${1} ]; then
    # ----
    stderr "ERROR: you need to set ${2}"
    # ----

    exit 1
else
    # ----
    stdout "OK: ${2} set"
    # ----
fi
}


echo "     _ _     _ _             _ _ "
echo "    |   \   /   |           (_)_)"
echo "    | |\ \ / /| | __ _  __ _ _ _ _  __   __"
echo "    | | \ _ / | |/ _\` |/ _\` | | | '_  \\/ __|"
echo "    | |       | | (_| | (_| | | | | | |\\__ \\"
echo "    |_|       |_|\__,_|\__,_|_|_|_| |_||__ /"

# ----
stdout "Checking requirements..."
# ----

exists ${MYSQL_SOURCE_ADDRESS} "MYSQL_SOURCE_ADDRESS"
exists ${MYSQL_SOURCE_USER} "MYSQL_SOURCE_USER"
exists ${MYSQL_SOURCE_PASSWORD} "MYSQL_SOURCE_PASSWORD"
exists ${MYSQL_SOURCE_DATABASE} "MYSQL_SOURCE_DATABASE"
exists ${MYSQL_TARGET_ADDRESS} "MYSQL_TARGET_ADDRESS"
exists ${MYSQL_TARGET_USER} "MYSQL_TARGET_USER"
exists ${MYSQL_TARGET_PASSWORD} "MYSQL_TARGET_PASSWORD"
exists ${MYSQL_TARGET_DATABASE} "MYSQL_TARGET_DATABASE"

if [ -z ${MYSQL_SOURCE_PORT} ]; then
    # ----
    stdout "INFO: MYSQL_SOURCE_PORT not set, default 3306"
    # ----

    MYSQL_SOURCE_PORT=3306
fi

if [ -z ${MYSQL_TARGET_PORT} ]; then
    # ----
    stdout "INFO: MYSQL_TARGET_PORT not set, default 3306"
    # ----

    MYSQL_TARGET_PORT=3306
fi

# ----
stdout "Successfully checked requirements!"
# ----

# ----
stdout "Begin transaction $(date)"
# ----

mysqldump -v --user="${MYSQL_SOURCE_USER}" --password="${<PASSWORD>}" --host="${MYSQL_SOURCE_ADDRESS}" --port="${MYSQL_SOURCE_PORT}" --routines --triggers "${MYSQL_SOURCE_DATABASE}" > /sql/database.sql

mysql -v --user="${MYSQL_TARGET_USER}" --password="${<PASSWORD>}" --host="${MYSQL_TARGET_ADDRESS}" --port="${MYSQL_TARGET_PORT}" "${MYSQL_TARGET_DATABASE}" < /sql/database.sql


if [ -e /sql/source.sql ]; then
    # ----
    stdout "Execute script on source"
    # ----

{'fraction_non_alphanumeric': 0.2058898847631242, 'fraction_numerical': 0.012291933418693982, 'mean_word_length': 2.640260950605778, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1263666', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1531, 'n_words': 263}