-
-
Notifications
You must be signed in to change notification settings - Fork 28
[#1895] Added fresh DB download support for Acquia. #2120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughRenames the DB download flag from Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Ahoy as ahoy/download-db
participant Script as download-db-acquia.sh
participant Acquia as Acquia API
participant Poller as Status Poller
User->>Ahoy: ahoy download-db --fresh
Ahoy->>Script: export VORTEX_DB_DOWNLOAD_FRESH=1
rect rgb(245,250,255)
Note over Script,Acquia: Fresh-backup flow (new)
Script->>Acquia: POST /backups (create backup)
Acquia-->>Script: 202 + notification URL
Script->>Poller: start polling notification URL (interval configurable)
loop Poll until completed/failed or timeout
Poller->>Acquia: GET backup status
Acquia-->>Poller: status (pending|completed|failed)
end
Poller-->>Script: final status (completed|failed|timeout)
end
rect rgb(245,255,245)
Note over Script,Acquia: Existing discovery & download flow
Script->>Acquia: GET latest backup/metadata
Acquia-->>Script: download URL
Script->>Acquia: GET backup file
Acquia-->>Script: backup archive
Script->>Script: extract -> .data/db.sql
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (7)
🧰 Additional context used🧠 Learnings (3)📚 Learning: 2025-11-24T21:29:10.867ZApplied to files:
📚 Learning: 2025-11-24T21:29:10.867ZApplied to files:
📚 Learning: 2025-08-08T12:02:24.652ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
🔇 Additional comments (5)
Comment |
e5ad782 to
22ed624
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (6)
.ahoy.yml(1 hunks).vortex/docs/content/workflows/development.mdx(1 hunks).vortex/docs/content/workflows/variables.mdx(2 hunks).vortex/tests/bats/unit/download-db-acquia.bats(1 hunks)scripts/vortex/download-db-acquia.sh(2 hunks)scripts/vortex/download-db-lagoon.sh(3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-08T12:02:24.652Z
Learnt from: AlexSkrypnyk
Repo: drevops/vortex PR: 1896
File: .vortex/tests/bats/unit/download-db-lagoon.bats:24-25
Timestamp: 2025-08-08T12:02:24.652Z
Learning: In .vortex/tests/bats/unit Bats tests using ../_helper.bash (run_steps), prefixing a STEPS entry with "- " denotes a negative assertion (the substring must NOT appear in output). Unprefixed entries are positive assertions. Example: "- Database dump refresh requested. Will create a new dump." asserts absence; "Database dump refresh requested. Will create a new dump." asserts presence.
Applied to files:
.vortex/tests/bats/unit/download-db-acquia.bats
🧬 Code graph analysis (1)
scripts/vortex/download-db-acquia.sh (2)
scripts/vortex/download-db-lagoon.sh (4)
task(74-74)note(73-73)fail(77-77)pass(76-76)scripts/vortex/task-copy-files-acquia.sh (1)
extract_json_value(72-75)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: build (0)
- GitHub Check: build (1)
- GitHub Check: vortex-test-workflow (2)
- GitHub Check: vortex-test-workflow (1)
- GitHub Check: vortex-test-workflow (3)
- GitHub Check: vortex-test-workflow (4)
- GitHub Check: vortex-test-workflow (0)
- GitHub Check: vortex-test-installer (8.3)
- GitHub Check: vortex-test-installer (8.4)
🔇 Additional comments (3)
.vortex/docs/content/workflows/development.mdx (1)
46-51: Docs correctly describe new--freshbehaviorThe updated wording around
ahoy fetch-db --freshaligns with the new fresh-backup workflow and cache semantics in the scripts..ahoy.yml (1)
121-127: CLI flag wiring for--freshlooks correctThe updated usage string and
casemapping from--freshtoVORTEX_DB_DOWNLOAD_FRESH=1correctly expose the fresh-backup behavior through Ahoy without affecting default downloads..vortex/docs/content/workflows/variables.mdx (1)
589-603: New backup-wait and fresh-flag variables are documented consistentlyDescriptions, defaults, and “Defined or used in” references align with the Acquia script behavior and Lagoon integration.
Also applies to: 631-637
| @test "download-db-acquia: Create fresh backup when requested" { | ||
| pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
|
||
| # Clean up any existing test files | ||
| rm -rf .data | ||
| mkdir -p .data | ||
|
|
||
| # Create .env.local with the fresh flag | ||
| echo "VORTEX_DB_DOWNLOAD_FRESH=1" > .env.local | ||
|
|
||
| declare -a STEPS=( | ||
| "[INFO] Started database dump download from Acquia." | ||
|
|
||
| # Authentication | ||
| "[TASK] Retrieving authentication token." | ||
| '@curl -s -L https://accounts.acquia.com/api/auth/oauth/token --data-urlencode client_id=test-key --data-urlencode client_secret=test-secret --data-urlencode grant_type=client_credentials # {"access_token":"test-token","expires_in":3600}' | ||
|
|
||
| # Application UUID | ||
| "[TASK] Retrieving testapp application UUID." | ||
| '@curl -s -L -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://cloud.acquia.com/api/applications?filter=name%3Dtestapp # {"_embedded":{"items":[{"uuid":"app-uuid-123","name":"testapp"}]}}' | ||
|
|
||
| # Environment ID | ||
| "[TASK] Retrieving prod environment ID." | ||
| '@curl -s -L -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://cloud.acquia.com/api/applications/app-uuid-123/environments?filter=name%3Dprod # {"_embedded":{"items":[{"id":"env-id-456","name":"prod"}]}}' | ||
|
|
||
| # Create backup | ||
| "[TASK] Creating new database backup for testdb." | ||
| '@curl -s -L -X POST -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://cloud.acquia.com/api/environments/env-id-456/databases/testdb/backups # {"_links":{"notification":{"href":"https://cloud.acquia.com/api/notifications/notification-uuid-123"}}}' | ||
|
|
||
| # Wait for backup - mock status checks | ||
| "[TASK] Waiting for backup to complete." | ||
| '@sleep 10 # 0' | ||
| '@curl -s -L -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://cloud.acquia.com/api/notifications/notification-uuid-123 # {"status":"in-progress"}' | ||
| " Backup in progress (10s elapsed)..." | ||
| '@sleep 10 # 0' | ||
| '@curl -s -L -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://cloud.acquia.com/api/notifications/notification-uuid-123 # {"status":"completed"}' | ||
| "[ OK ] Backup completed successfully." | ||
| " Fresh backup will be downloaded." | ||
|
|
||
| # Continue with normal download flow | ||
| "[TASK] Discovering latest backup ID for DB testdb." | ||
| '@curl --progress-bar -L -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://cloud.acquia.com/api/environments/env-id-456/databases/testdb/backups?sort=created # {"_embedded":{"items":[{"id":"backup-id-new-123","completed":"2024-01-02T00:00:00+00:00"}]}}' | ||
|
|
||
| # Rest of download steps... | ||
| "[TASK] Discovering backup URL." | ||
| '@curl --progress-bar -L -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://cloud.acquia.com/api/environments/env-id-456/databases/testdb/backups/backup-id-new-123/actions/download # {"url":"https://backup.example.com/db-fresh.sql.gz"}' | ||
|
|
||
| "[TASK] Downloading DB dump into file .data/testdb_backup_backup-id-new-123.sql.gz." | ||
| '@curl --progress-bar -L -H Accept: application/json, version=2 -H Authorization: Bearer test-token https://backup.example.com/db-fresh.sql.gz -o .data/testdb_backup_backup-id-new-123.sql.gz # 0 # # echo "CREATE TABLE fresh (id INT);" | gzip > .data/testdb_backup_backup-id-new-123.sql.gz' | ||
|
|
||
| "[TASK] Expanding DB file .data/testdb_backup_backup-id-new-123.sql.gz into .data/testdb_backup_backup-id-new-123.sql." | ||
| "@gunzip -t .data/testdb_backup_backup-id-new-123.sql.gz # 0" | ||
| "@gunzip -c .data/testdb_backup_backup-id-new-123.sql.gz # 0 # CREATE TABLE fresh (id INT);" | ||
|
|
||
| '[TASK] Renaming file ".data/testdb_backup_backup-id-new-123.sql" to ".data/db.sql".' | ||
| '@mv .data/testdb_backup_backup-id-new-123.sql .data/db.sql # 0 # # echo "CREATE TABLE fresh (id INT);" > .data/db.sql' | ||
|
|
||
| "[ OK ] Finished database dump download from Acquia." | ||
| ) | ||
|
|
||
| export VORTEX_ACQUIA_KEY="test-key" | ||
| export VORTEX_ACQUIA_SECRET="test-secret" | ||
| export VORTEX_ACQUIA_APP_NAME="testapp" | ||
| export VORTEX_DB_DOWNLOAD_ENVIRONMENT="prod" | ||
| export VORTEX_DB_DOWNLOAD_ACQUIA_DB_NAME="testdb" | ||
| export VORTEX_DB_DIR=".data" | ||
| export VORTEX_DB_FILE="db.sql" | ||
| export VORTEX_DB_DOWNLOAD_FRESH="1" | ||
|
|
||
| mocks="$(run_steps "setup")" | ||
| run scripts/vortex/download-db-acquia.sh | ||
| run_steps "assert" "${mocks}" | ||
|
|
||
| assert_success | ||
| assert_file_exists ".data/db.sql" | ||
| assert_file_contains ".data/db.sql" "CREATE TABLE fresh" | ||
|
|
||
| rm -rf .data | ||
| popd >/dev/null | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isolate .env.local changes to avoid leaking state into other tests
This test overwrites .env.local in LOCAL_REPO_DIR and never restores it. That can:
- Permanently change a developer’s local
.env.localif tests run in the real repo. - Cause later tests (in this or other Bats files) to always see
VORTEX_DB_DOWNLOAD_FRESH=1via.env.local, even when they don’t export it explicitly. Based on learnings, STEPS rely on clean output state.
A safer pattern is to backup any existing .env.local, write the test-specific one, then restore or delete it at the end:
@test "download-db-acquia: Create fresh backup when requested" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
- # Clean up any existing test files
+ # Clean up any existing test files
rm -rf .data
mkdir -p .data
- # Create .env.local with the fresh flag
- echo "VORTEX_DB_DOWNLOAD_FRESH=1" > .env.local
+ # Backup existing .env.local (if any) and create test-specific one
+ local env_local_backup=""
+ if [ -f .env.local ]; then
+ env_local_backup=".env.local.bak-download-db-acquia-fresh"
+ cp .env.local "${env_local_backup}"
+ fi
+ echo "VORTEX_DB_DOWNLOAD_FRESH=1" > .env.local
@@
assert_file_exists ".data/db.sql"
assert_file_contains ".data/db.sql" "CREATE TABLE fresh"
- rm -rf .data
- popd >/dev/null
+ rm -rf .data
+ if [ -n "${env_local_backup}" ] && [ -f "${env_local_backup}" ]; then
+ mv "${env_local_backup}" .env.local
+ else
+ rm -f .env.local
+ fi
+ popd >/dev/null
}This keeps the test hermetic while preserving any pre-existing .env.local.
🤖 Prompt for AI Agents
.vortex/tests/bats/unit/download-db-acquia.bats around lines 449-528: the test
writes .env.local and never restores it, leaking state to other tests or a
developer repo; modify the test to (1) detect and save any existing .env.local
(e.g., move to a temp path), (2) create the test-specific .env.local, (3) ensure
cleanup in all exit paths by restoring the original .env.local if it existed or
deleting the test file otherwise (use a trap or explicit cleanup before
returning), and (4) keep the rest of the test identical so environment variables
are only present for the duration of the test.
| # Flag to download a fresh copy of the database by triggering a new backup. | ||
| VORTEX_DB_DOWNLOAD_FRESH="${VORTEX_DB_DOWNLOAD_FRESH:-}" | ||
|
|
||
| # Interval in seconds to wait between backup status checks. | ||
| VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_WAIT_INTERVAL="${VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_WAIT_INTERVAL:-10}" | ||
|
|
||
| # Maximum time in seconds to wait for backup completion. | ||
| VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_MAX_WAIT="${VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_MAX_WAIT:-600}" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate backup wait interval/max wait to prevent hangs on bad config
The fresh-backup workflow and polling logic are solid, but VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_WAIT_INTERVAL and VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_MAX_WAIT are used as raw integers without validation. If a user sets WAIT_INTERVAL=0 (or non‑numeric), the loop can hang or misbehave.
Adding simple numeric/positive validation before the loop will make this more robust:
if [ "$VORTEX_DB_DOWNLOAD_FRESH" == "1" ]; then
task "Creating new database backup for ${VORTEX_DB_DOWNLOAD_ACQUIA_DB_NAME}."
@@
task "Waiting for backup to complete."
max_wait="${VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_MAX_WAIT}"
wait_interval="${VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_WAIT_INTERVAL}"
elapsed=0
+
+ # Validate wait_interval and max_wait to avoid hangs on misconfiguration.
+ if ! [[ "${wait_interval}" =~ ^[0-9]+$ ]] || [ "${wait_interval}" -le 0 ]; then
+ fail "VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_WAIT_INTERVAL must be a positive integer, got '${wait_interval}'."
+ exit 1
+ fi
+ if ! [[ "${max_wait}" =~ ^[0-9]+$ ]] || [ "${max_wait}" -le 0 ]; then
+ fail "VORTEX_DB_DOWNLOAD_ACQUIA_BACKUP_MAX_WAIT must be a positive integer, got '${max_wait}'."
+ exit 1
+ fi
while [ ${elapsed} -lt ${max_wait} ]; do
sleep ${wait_interval}(You can also switch the surrounding if [ "$VORTEX_DB_DOWNLOAD_FRESH" == "1" ] to use = for consistency with other scripts.)
Also applies to: 142-197
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2120 +/- ##
===========================================
- Coverage 75.57% 70.80% -4.77%
===========================================
Files 62 99 +37
Lines 2968 5059 +2091
Branches 44 44
===========================================
+ Hits 2243 3582 +1339
- Misses 725 1477 +752 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
22ed624 to
28e527f
Compare
28e527f to
1e5b029
Compare
1e5b029 to
65eda95
Compare
65eda95 to
ada104e
Compare
ada104e to
2e2742c
Compare
Closes #1895
Summary by CodeRabbit
New Features
Documentation
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.