#!/usr/bin/env bash # Prepare some colors. red=$(tput -T xterm-256color setaf 1) aqua=$(tput -T xterm-256color setaf 14) no_color=$(tput -T xterm-256color sgr0) # Add info about restoring. printf "%s[%s] %sExecuting SQL files...\n" "${aqua}" "${DDEV_SITENAME^}" "${no_color}" # List of SQL files to be imported, in the desired order. sql_files=( "init.sql" "v2.sql" "v3.sql" "2022-07-29-s3-regions.sql" "2022-10-01-emails-json.sql" "2022-10-06-timestamp-nullable.sql" "2022-10-10-campaigns.sql" "2022-10-12-add-render-style.sql" "2023-01-06-add-preference-center.sql" "2023-01-22-email-and-options.sql" "2023-01-25-email-object-creation.sql" ) # Loop over each SQL file and execute it. for file in "${sql_files[@]}"; do if [ -f "${DDEV_APPROOT}/sql/$file" ]; then # Execute the SQL file using mysql inside the DDEV environment. ddev mysql -uroot -proot < "${DDEV_APPROOT}/sql/$file" # Check status code from the execution command. status=$? if [ $status != 0 ]; then # Add info about errors that were detected. printf "%s[%s] %sError executing file $file. Check the errors before you can continue.%s\n" "${aqua}" "${DDEV_SITENAME^}" "${red}" "${no_color}" # Exit the script if an error occurs. exit 1 fi else # File not found, print a warning. printf "%s[%s] %sFile $file not found in sql directory.%s\n" "${aqua}" "${DDEV_SITENAME^}" "${red}" "${no_color}" fi done # Add ending info about SQL execution status. printf "%s[%s] %sSuccessfully executed all SQL files!\n" "${aqua}" "${DDEV_SITENAME^}" "${no_color}"