diff --git a/local/bin/db-rebuild.sh b/local/bin/db-rebuild.sh index 11805fc..79106de 100755 --- a/local/bin/db-rebuild.sh +++ b/local/bin/db-rebuild.sh @@ -6,7 +6,9 @@ USER=${DB_USER:-${MYSQL_USER:-root}} PASSWORD=${DB_PASSWORD:-${MYSQL_PASSWORD:-}} DATABASE=${DB_NAME:-${MYSQL_DATABASE:-database}} PORT=${DB_PORT:-${MYSQL_TCP_PORT:-3306}} -WEBROOT=${LANDO_WEBROOT:-$(dirname $(dirname $(realpath $0)))} +WEBROOT=${WORKSPACE_FOLDER:-$(dirname $(dirname $(realpath $0)))} +DRUSH_BIN=${WEBROOT}/vendor/bin/drush +DRUSH=${DRUSH_BIN:-drush} DRUSHTASK=${DRUSH_TASK:-deploy} TERMINUSENV=${TERMINUS_ENV:-dev} @@ -157,4 +159,4 @@ echo "Import completed with status code $?" # update db with latest code/config changes echo "Running drush:$DRUSHTASK to update DB with latest configs and baseline migrations." -eval "cd $WEBROOT && drush $DRUSHTASK" \ No newline at end of file +eval "cd $WEBROOT && $DRUSH $DRUSHTASK" diff --git a/local/etc/uceap.d/devcontainer_reset_db.sh b/local/etc/uceap.d/devcontainer_reset_db.sh index ef1b5bc..c42b673 100644 --- a/local/etc/uceap.d/devcontainer_reset_db.sh +++ b/local/etc/uceap.d/devcontainer_reset_db.sh @@ -1,7 +1,28 @@ function devcontainer_reset_db() { # Detect the compose project by inspecting the current container + local CURRENT_CONTAINER + local COMPOSE_PROJECT + local WORKSPACE_NAME + local CONTAINER_NAME + local VOLUME_NAME CURRENT_CONTAINER=$(hostname) echo "Running from container: $CURRENT_CONTAINER" + local skip_deploy=false + + # Loop through all arguments passed to the function + while [[ $# -gt 0 ]]; do + case "$1" in + -sd|--skip-deploy) + skip_deploy=true + shift + ;; + *) + echo "Unknown option: $1" >&2 + return 1 + ;; + esac + done + # Get the compose project name from the current container's labels COMPOSE_PROJECT=$(docker inspect "$CURRENT_CONTAINER" --format '{{index .Config.Labels "com.docker.compose.project"}}' 2>/dev/null) @@ -43,15 +64,15 @@ function devcontainer_reset_db() { echo "Found volume: $VOLUME_NAME" # Stop and remove the container - docker compose -p "$COMPOSE_PROJECT" -f .devcontainer/docker-compose.yml stop mariadb - docker compose -p "$COMPOSE_PROJECT" -f .devcontainer/docker-compose.yml rm -f mariadb + docker compose -p "$COMPOSE_PROJECT" -f .devcontainer/docker-compose.yml stop mariadb || return 1 + docker compose -p "$COMPOSE_PROJECT" -f .devcontainer/docker-compose.yml rm -f mariadb || return 1 # Remove the volume echo "Removing volume: $VOLUME_NAME" - docker volume rm "$VOLUME_NAME" + docker volume rm "$VOLUME_NAME" || return 1 # Start the container with a fresh volume - docker compose -p "$COMPOSE_PROJECT" -f .devcontainer/docker-compose.yml up -d mariadb + docker compose -p "$COMPOSE_PROJECT" -f .devcontainer/docker-compose.yml up -d mariadb || return 1 echo "Waiting for database to be ready..." sleep 5 @@ -59,8 +80,14 @@ function devcontainer_reset_db() { # Clear Drupal cache since the database was reset echo "Clearing Drupal cache..." _cwd_workspace - drush cache-rebuild + drush cache-rebuild || return 1 + # Check if skip-deploy not passed as option and run deploy + if [ "$skip_deploy" = false ]; then + echo "Re-import local Drupal changes..." + _cwd_workspace + drush deploy || return 1 + fi echo "Database reset complete!" } @@ -72,6 +99,7 @@ Resets the devcontainer database to its original state by recreating the mariadb ``` bash uceap devcontainer-reset-db +uceap devcontainer-reset-db --skip-deploy ``` ## Description @@ -82,6 +110,8 @@ This command is faster than `uceap refresh-content` when you only need to reset 2. Removing the anonymous volume that contains the modified database data 3. Recreating the container from the image with baked-in seed data +Use `--skip-deploy` to skip `drush deploy` after the reset. + This is useful after running e2e tests that modify the database (e.g., submitting an application). The database container image has seed data pre-baked, so resetting to a clean state is much faster than downloading and importing a SQL dump from Pantheon. **Note:** This command only works in devcontainers and will not work in CI or other environments.