-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for test loading SQL in MySQL
- Loading branch information
1 parent
7ed6c8e
commit bf7240d
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
if [[ -z "$1" ]]; | ||
then | ||
sql_dir="sql" | ||
else | ||
sql_dir=$1 | ||
fi | ||
|
||
if [[ ! -d "$sql_dir" ]]; | ||
then | ||
echo "Error: SQL directory $sql_dir does not exist. Please run scripts/generate-sql-files.sh first." | ||
exit 1 | ||
fi | ||
|
||
# Initialize a variable to track if any command fails | ||
error_occurred=0 | ||
|
||
for yaml_file in yml/*.yaml; do | ||
echo "Loading SQL for ${yaml_file}..." | ||
sql_file="$sql_dir/$(basename "$yaml_file" .yaml).sql" | ||
if [[ ! -f "$sql_file" ]]; then | ||
echo "SQL file $sql_file does not exist. Skipping." | ||
continue | ||
fi | ||
db_name=$(yq e '.name' "$yaml_file") | ||
mysql -e "DROP DATABASE IF EXISTS ${db_name};" | ||
mysql -e "CREATE DATABASE ${db_name};" | ||
mysql -q < "$sql_file" | ||
# Check if the mysql command was successful | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to load SQL from $sql_file" | ||
error_occurred=1 | ||
else | ||
echo "Done loading SQL from $sql_file" | ||
fi | ||
done | ||
|
||
# Exit with non-zero status if any command failed | ||
if [ $error_occurred -ne 0 ]; then | ||
echo "Error: Failed to load all SQL files into MySQL" | ||
exit 1 | ||
fi |