Skip to content

Commit 2bb1c07

Browse files
committed
[#1668] Allow to import from a custom file using ahoy import.
1 parent fc806ef commit 2bb1c07

6 files changed

Lines changed: 62 additions & 20 deletions

File tree

.ahoy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ commands:
148148

149149
import-db:
150150
usage: Import database from dump.
151-
cmd: VORTEX_PROVISION_POST_OPERATIONS_SKIP=1 ahoy cli ./scripts/vortex/provision.sh
151+
cmd: VORTEX_PROVISION_POST_OPERATIONS_SKIP=1 VORTEX_PROVISION_DB="$@" ahoy cli ./scripts/vortex/provision.sh
152152

153153
pull-db:
154154
usage: Download database image with the latest nightly dump. Run "ahoy reload-db" to reload DB in the running stack.

.vortex/docs/content/workflows/variables.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,14 @@ Default value: `UNDEFINED`
14811481

14821482
Defined in: `ACQUIA ENVIRONMENT`
14831483

1484+
### `VORTEX_PROVISION_DB`
1485+
1486+
Provision database dump file.<br/>If not set, it will be auto-discovered from the VORTEX_DB_DIR directory using<br/>the VORTEX_DB_FILE name.
1487+
1488+
Default value: `UNDEFINED`
1489+
1490+
Defined in: `scripts/vortex/provision.sh`
1491+
14841492
### `VORTEX_PROVISION_OVERRIDE_DB`
14851493

14861494
Overwrite a database if it exists.
@@ -1545,6 +1553,14 @@ Default value: `UNDEFINED`
15451553

15461554
Defined in: `.env`, `scripts/vortex/provision.sh`
15471555

1556+
### `VORTEX_PROVISION_SCRIPTS_DIR`
1557+
1558+
Directory with custom provision scripts.
1559+
1560+
Default value: `./scripts/custom`
1561+
1562+
Defined in: `scripts/vortex/provision.sh`
1563+
15481564
### `VORTEX_PROVISION_SKIP`
15491565

15501566
Flag to skip site provisioning.

.vortex/installer/tests/Fixtures/install/_baseline/.ahoy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ commands:
141141

142142
import-db:
143143
usage: Import database from dump.
144-
cmd: VORTEX_PROVISION_POST_OPERATIONS_SKIP=1 ahoy cli ./scripts/vortex/provision.sh
144+
cmd: VORTEX_PROVISION_POST_OPERATIONS_SKIP=1 VORTEX_PROVISION_DB="$@" ahoy cli ./scripts/vortex/provision.sh
145145

146146
pull-db:
147147
usage: Download database image with the latest nightly dump. Run "ahoy reload-db" to reload DB in the running stack.

.vortex/tests/bats/_helper.workflow.bash

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ assert_ahoy_login() {
325325

326326
assert_ahoy_export_db() {
327327
step "Export DB"
328-
file="${1:-mydb.sql}"
328+
329+
file="${1:-}"
329330
run ahoy export-db "${file}"
331+
330332
assert_success
331333
assert_output_not_contains "Containers are not running."
332334
sync_to_host
@@ -335,7 +337,9 @@ assert_ahoy_export_db() {
335337

336338
assert_ahoy_import_db() {
337339
step "Import DB"
338-
run ahoy import-db
340+
341+
run ahoy import-db "${1-}"
342+
339343
assert_success
340344
assert_output_contains "Provisioning site from the database dump file."
341345
assert_output_not_contains "Running deployment operations via 'drush deploy:hook'."

.vortex/tests/bats/workflow.install.db.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ load _helper.workflow.bash
3434

3535
assert_ahoy_login
3636

37+
# Export to default file.
3738
assert_ahoy_export_db
3839

40+
# Export to custom file.
41+
assert_ahoy_export_db "mydb.sql"
42+
43+
# Import from default file.
3944
assert_ahoy_import_db
4045

46+
# Import from custom file.
47+
assert_ahoy_import_db "mydb.sql"
48+
4149
assert_ahoy_lint
4250

4351
assert_ahoy_test

scripts/vortex/provision.sh

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ VORTEX_PROVISION_USE_MAINTENANCE_MODE="${VORTEX_PROVISION_USE_MAINTENANCE_MODE:-
3535
# state before any updates ran (for example, DB caching in CI).
3636
VORTEX_PROVISION_POST_OPERATIONS_SKIP="${VORTEX_PROVISION_POST_OPERATIONS_SKIP:-0}"
3737

38+
# Provision database dump file.
39+
# If not set, it will be auto-discovered from the VORTEX_DB_DIR directory using
40+
# the VORTEX_DB_FILE name.
41+
VORTEX_PROVISION_DB="${VORTEX_PROVISION_DB:-}"
42+
43+
# Directory with custom provision scripts.
44+
VORTEX_PROVISION_SCRIPTS_DIR="${VORTEX_PROVISION_SCRIPTS_DIR:-./scripts/custom}"
45+
3846
# Name of the webroot directory with Drupal codebase.
3947
WEBROOT="${WEBROOT:-web}"
4048

@@ -74,15 +82,19 @@ yesno() { [ "${1}" = "1" ] && echo "Yes" || echo "No"; }
7482

7583
info "Started site provisioning."
7684

77-
[ "${VORTEX_PROVISION_SKIP}" = "1" ] && pass "Skipped site provisioning as VORTEX_PROVISION_SKIP is set to 1." && exit 0
78-
79-
# Normalize the provision type.
80-
VORTEX_PROVISION_TYPE=${VORTEX_PROVISION_TYPE:-'database'}
81-
case ${VORTEX_PROVISION_TYPE} in database | profile) ;; *) VORTEX_PROVISION_TYPE='database' ;; esac
85+
if [ "${VORTEX_PROVISION_SKIP}" = "1" ]; then
86+
pass "Skipped site provisioning as VORTEX_PROVISION_SKIP is set to 1."
87+
info "Finished site provisioning."
88+
exit 0
89+
fi
8290

83-
## Convert DB dir starting with './' to a full path.
91+
# Convert DB dir starting with './' to a full path.
8492
[ "${VORTEX_DB_DIR#./}" != "${VORTEX_DB_DIR}" ] && VORTEX_DB_DIR="$(pwd)${VORTEX_DB_DIR#.}"
8593

94+
if [ -z "${VORTEX_PROVISION_DB}" ]; then
95+
VORTEX_PROVISION_DB="${VORTEX_PROVISION_DB:-"${VORTEX_DB_DIR}/${VORTEX_DB_FILE}"}"
96+
fi
97+
8698
drush_version="$(drush --version | cut -d' ' -f4)"
8799
drupal_version="$(drush status --field=drupal-version 2>/dev/null || echo "Unknown")"
88100
site_is_installed="$(drush status --fields=bootstrap 2>/dev/null | grep -q "Successful" && echo "1" || echo "0")"
@@ -92,9 +104,11 @@ if [ -z "${DRUPAL_CONFIG_PATH}" ]; then
92104
DRUPAL_CONFIG_PATH="$(drush php:eval 'print realpath(\Drupal\Core\Site\Settings::get("config_sync_directory"));')"
93105
[ ! -d "${DRUPAL_CONFIG_PATH}" ] && fail "Config directory \"${DRUPAL_CONFIG_PATH:-<empty>}\" does not exist." && exit 1
94106
fi
95-
96107
site_has_config="$(test "$(ls -1 ${DRUPAL_CONFIG_PATH}/*.yml 2>/dev/null | wc -l | tr -d ' ')" -gt 0 && echo "1" || echo "0")"
97108

109+
# Normalize the provision type.
110+
[ "${VORTEX_PROVISION_TYPE}" = "profile" ] || VORTEX_PROVISION_TYPE=database
111+
98112
################################################################################
99113
# Print provisioning information.
100114
################################################################################
@@ -107,7 +121,7 @@ note "Public files path : ${DRUPAL_PUBLIC_FILES-<empty>}"
107121
note "Private files path : ${DRUPAL_PRIVATE_FILES-<empty>}"
108122
note "Temporary files path : ${DRUPAL_TEMPORARY_FILES-<empty>}"
109123
note "Config files path : ${DRUPAL_CONFIG_PATH}"
110-
note "DB dump file path : ${VORTEX_DB_DIR}/${VORTEX_DB_FILE} ($([ -f "${VORTEX_DB_DIR}/${VORTEX_DB_FILE}" ] && echo "present" || echo "absent"))"
124+
note "DB dump file path : ${VORTEX_PROVISION_DB} ($([ -f "${VORTEX_PROVISION_DB}" ] && echo "present" || echo "absent"))"
111125
if [ -n "${VORTEX_DB_IMAGE:-}" ]; then
112126
note "DB dump container image : ${VORTEX_DB_IMAGE}"
113127
fi
@@ -128,17 +142,17 @@ echo
128142
# Provision site by importing the database from the dump file.
129143
#
130144
provision_from_db() {
131-
if [ ! -f "${VORTEX_DB_DIR}/${VORTEX_DB_FILE}" ]; then
145+
if [ ! -f "${VORTEX_PROVISION_DB}" ]; then
132146
echo
133147
fail "Unable to import database from file."
134-
note "Dump file ${VORTEX_DB_DIR}/${VORTEX_DB_FILE} does not exist."
148+
note "Dump file ${VORTEX_PROVISION_DB} does not exist."
135149
note "Site content was not changed."
136150
exit 1
137151
fi
138152

139153
drush sql:drop
140154

141-
drush sql:cli <"${VORTEX_DB_DIR}/${VORTEX_DB_FILE}"
155+
drush sql:cli <"${VORTEX_PROVISION_DB}"
142156

143157
pass "Imported database from the dump file."
144158
}
@@ -177,7 +191,7 @@ provision_from_profile() {
177191
# sufficient output for debugging.
178192
if [ "${VORTEX_PROVISION_TYPE}" = "database" ]; then
179193
info "Provisioning site from the database dump file."
180-
note "Dump file path: ${VORTEX_DB_DIR}/${VORTEX_DB_FILE}"
194+
note "Dump file path: ${VORTEX_PROVISION_DB}"
181195

182196
if [ "${site_is_installed}" = "1" ]; then
183197
note "Existing site was found when provisioning from the database dump file."
@@ -292,10 +306,10 @@ else
292306
fi
293307

294308
# Run custom provision scripts.
295-
# The files should be located in "./scripts/custom/" directory
296-
# and must have "provision-" prefix and ".sh" extension.
297-
if [ -d "./scripts/custom" ]; then
298-
for file in ./scripts/custom/provision-*.sh; do
309+
# The files should be located in VORTEX_PROVISION_SCRIPTS_DIR directory,
310+
# must have "provision-" prefix and ".sh" extension.
311+
if [ -d "${VORTEX_PROVISION_SCRIPTS_DIR}" ]; then
312+
for file in "${VORTEX_PROVISION_SCRIPTS_DIR}"/provision-*.sh; do
299313
if [ -f "${file}" ]; then
300314
task "Running custom post-install script '${file}'."
301315
echo

0 commit comments

Comments
 (0)