Skip to content

Commit d9d33c8

Browse files
committed
ref data import
1 parent 597066d commit d9d33c8

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

drupal/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: drupal
3-
version: 1.20.0
3+
version: 1.21.0
44
dependencies:
55
- name: mariadb
66
version: 7.5.x

drupal/templates/_helpers.tpl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,21 +535,51 @@ else
535535
fi
536536
{{- end }}
537537

538-
{{- define "drupal.import-reference-db" -}}
538+
{{- define "drupal.import-reference-db" -}}
539539
if [ "${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

drupal/values.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"branchName": { "type": "string" },
99
"imagePullSecrets": { "type": "array" },
1010
"imagePullSecret": { "type": "string" },
11-
"serviceAccount": {
11+
"serviceAccount": {
1212
"type": "object",
1313
"additionalProperties": false,
1414
"properties": {
@@ -450,6 +450,7 @@
450450
"enabled": { "type": "boolean" },
451451
"referenceEnvironment": { "type": "string" },
452452
"schedule": { "type": "string" },
453+
"databaseImportMethod": { "type": "string" },
453454
"copyDatabase": { "type": "boolean" },
454455
"copyFiles": { "type": "boolean" },
455456
"updateAfterDeployment": { "type": "boolean" },

drupal/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ referenceData:
448448
# When to automatically update the reference data.
449449
schedule: '~ 3 * * *'
450450

451+
# The method used to import the database tables. Can be either 'parallel' or 'sequential'.
452+
# Parallel is faster but might in some cases be unstable. In that case, use sequential instead.
453+
databaseImportMethod: 'parallel'
454+
451455
# Whether to copy the database, only used programmatically.
452456
copyDatabase: true
453457

0 commit comments

Comments
 (0)