@@ -535,21 +535,51 @@ else
535535fi
536536{{- end }}
537537
538- {{- define " drupal.import-reference-db" -}}
538+ {{- define " drupal.import-reference-db" -}}
539539if [ " ${REF_DATA_COPY_DB:-}" == " true" ]; then
540540 if [[ -f /app/reference-data/db.tar.gz || -f /app/reference-data/db.sql.gz ]]; then
541541 echo " Dropping old database"
542542 drush sql-drop -y
543543
544544 app_ref_data= /app/reference-data
545545 tmp_ref_data= /tmp/reference-data
546+ import_method= {{ .Values.referenceData.databaseImportMethod }}
546547
547548 # New way of importing.
548549 if [[ -f " ${app_ref_data}/db.tar.gz" ]]; then
549550 echo " Importing reference database dump from db.tar.gz"
550551 mkdir " ${tmp_ref_data}"
551552 tar -xzf " ${app_ref_data}/db.tar.gz" -C " ${tmp_ref_data}/"
552- find " ${tmp_ref_data}/" -type f -name " *.sql" | xargs -P10 -I{} sh -c 'echo " Importing {}" && mysql -A --user= " ${DB_USER}" --password= " ${DB_PASS}" --host= " ${DB_HOST}" " ${DB_NAME}" < {}'
553+
554+ if [[ " $import_method" == " parallel" ]]; then
555+ echo " Importing SQL files in parallel. This setting can be changed in silta.yml using the referenceData.databaseImportMethod key."
556+ find " ${tmp_ref_data}/" -type f -name " *.sql" | xargs -P10 -I{} sh -c 'echo " Importing {}" && mysql -A --user= " ${DB_USER}" --password= " ${DB_PASS}" --host= " ${DB_HOST}" " ${DB_NAME}" < {}'
557+ pipeline_exit_code= $ ? # Capture exit code of the pipeline (most likely influenced by xargs)
558+
559+ # Check if xargs reported an error (any non-zero exit status)
560+ if [ " $pipeline_exit_code" -ne 0 ]; then
561+ echo " ERROR: One or more parallel imports failed. Check the logs above for specific mysql errors."
562+ exit 1
563+ fi
564+
565+ echo " Parallel import command finished."
566+
567+ elif [[ " $import_method" == " sequential" ]]; then
568+ echo " Importing SQL files sequentially. This setting can be changed in silta.yml using the referenceData.databaseImportMethod key."
569+ find " ${tmp_ref_data}/" -type f -name " *.sql" | sort | while IFS= read -r sql_file; do
570+ echo " Importing ${sql_file}"
571+ if ! mysql -A --user= " ${DB_USER}" --password= " ${DB_PASS}" --host= " ${DB_HOST}" " ${DB_NAME}" < " ${sql_file}" ; then
572+ echo " ERROR: Failed to import ${sql_file}. Check the logs above for specific mysql errors."
573+ exit 1
574+ fi
575+ done
576+
577+ echo " Sequential import command finished."
578+
579+ else
580+ echo " Incompatible import method. Please use either 'parallel' or 'sequential' in referenceData.databaseImportMethod."
581+ exit 1
582+ fi
553583
554584 # Backwards compatibility for old way of importing.
555585 elif [[ -f " ${app_ref_data}/db.sql.gz" ]]; then
0 commit comments