Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions test/create_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@ function create_empty_db() {
local db="${1}"
local dbconn="${2}"
create_script="drop database if exists \`${db}\`; create database if not exists \`${db}\`;"
mysql ${dbconn} -e "${create_script}" || exit_err "unable to create ${db}"
mysql ${dbconn} -e "${create_script}" || exit_err "unable to create ${db} on ${cbconn}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Suggested change
mysql ${dbconn} -e "${create_script}" || exit_err "unable to create ${db} on ${cbconn}"
mysql ${dbconn} -e "${create_script}" || exit_err "unable to create ${db} on ${dbconn}"

}

# set db connection for if running in a separate container or not
dbconn="-u root"
if [[ $MYSQL_CONTAINER ]]
then
dbconn="-u root -h ${DB_HOST} --port ${DB_PORT}"
fi
dbconn="-u root -h ${DB_HOST} --port ${DB_PORT}"

if ! mysql ${dbconn} -e "select 1" >/dev/null 2>&1; then
exit_err "unable to connect to ${DB_HOST}:${DB_PORT}"
Expand Down Expand Up @@ -94,26 +89,20 @@ for db in $DBS; do
r=`sql-migrate up -config="${DB_CONFIG_FILE}" -env="${dbname}" | xargs -0 echo`
if [[ "${r}" == "Migration failed"* ]]
then
echo "Migration failed - dropping and recreating"
create_empty_db "${dbname}" "${dbconn}"
sql-migrate up -config="${DB_CONFIG_FILE}" -env="${dbname}" || exit_err "Migration failed after dropping and recreating"
echo "sql-migrate: ${r}"
echo "Try \`docker compose down --volumes\` and running again"
exit 1
else
echo "${r}"
echo "sql-migrate: ${r}"
fi

USERS_SQL="../db-users/${db}.sql"
if [[ ${SKIP_USERS} -eq 1 ]]
then
echo "Skipping user grants for ${dbname}"
else
if [[ $MYSQL_CONTAINER ]]
then
sed -e "s/'localhost'/'%'/g" < "${USERS_SQL}" | \
mysql ${dbconn} -D "${dbname}" -f || exit_err "Unable to add users from ${USERS_SQL}"
else
sed -e "s/'localhost'/'127.%'/g" < "${USERS_SQL}" | \
mysql ${dbconn} -D "${dbname}" -f || exit_err "Unable to add users from ${USERS_SQL}"
fi
sed -e "s/'localhost'/'%'/g" < "${USERS_SQL}" | \
mysql ${dbconn} -D "${dbname}" -f || exit_err "Unable to add users from ${USERS_SQL}"
echo "Added users from ${USERS_SQL}"
fi

Expand Down
2 changes: 0 additions & 2 deletions test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ rsyslogd
./test/wait-for-it.sh bpkimetal 8080

# create the databases
MYSQL_CONTAINER=1 \
DB_HOST="boulder-mariadb" \
DB_PORT=3306 \
DB_CONFIG_FILE="${DIR}/../sa/db/dbconfig.mariadb.yml" \
SKIP_CREATE=0 \
SKIP_USERS=0 \
"$DIR/create_db.sh"

MYSQL_CONTAINER=1 \
DB_HOST="boulder-vitess" \
DB_PORT=33577 \
DB_CONFIG_FILE="${DIR}/../sa/db/dbconfig.mysql8.yml" \
Expand Down