Let job fail, when an error occurs during the legacy test script

This commit is contained in:
Jan Böhmer 2023-05-07 02:38:54 +02:00
parent 19ae9e7456
commit d766f255ef

View file

@ -24,14 +24,31 @@
SQL_FILES_TO_TEST=("db_minimal.sql" "db_jbtronics.sql")
DB_NAME="test"
DB_USER="root"
DB_PASSWORD="root"
# Iterate over all given SQL files and import them into the mysql database with the given name, drop the database if it already exists before
for SQL_FILE in "${SQL_FILES_TO_TEST[@]}"
do
echo "Testing for $SQL_FILE"
mysql -u root -e "DROP DATABASE IF EXISTS $DB_NAME; CREATE DATABASE $DB_NAME;"
mysql -u $DB_USER --password=$DB_PASSWORD -e "DROP DATABASE IF EXISTS $DB_NAME; CREATE DATABASE $DB_NAME;"
# If the last command failed, exit the script
if [ $? -ne 0 ]; then
echo "Failed to create database $DB_NAME"
exit 1
fi
# Import the SQL file into the database. The file pathes are relative to the current script location
mysql -u root $DB_NAME < .github/assets/legacy_import/$SQL_FILE
mysql -u DB_USER --password=$DB_PASSWORD $DB_NAME < .github/assets/legacy_import/$SQL_FILE
# If the last command failed, exit the script
if [ $? -ne 0 ]; then
echo "Failed to import $SQL_FILE into database $DB_NAME"
exit 1
fi
# Run doctrine migrations, this will migrate the database to the current version. This process should not fail
php bin/console doctrine:migrations:migrate -n
# If the last command failed, exit the script
if [ $? -ne 0 ]; then
echo "Failed to migrate database $DB_NAME"
exit 1
fi
done