#!/bin/bash

AUTO_CONFIRM=false

# Check for -y flag
if [[ "$1" == "-y" ]]; then
  AUTO_CONFIRM=true
fi

# Prompt for confirmation unless auto-confirm is enabled
if [[ "$AUTO_CONFIRM" != "true" ]]; then
  read -p "This will drop the current database and import the init.sql.gz dump. Are you sure you want to continue? (y/N) " -n 1 -r
  echo  # move to a new line
  if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    echo "Skipping import... If the db is not already imported, you may need to run 'ddev init-db' manually."
    exit 0
  fi
else
  echo "Auto-confirming database drop and import..."
fi

# Remove the existing db.
ddev drush sql:drop -y

# Extract and import the dump.
ddev import-db --file=drupal/dump/init.sql.gz

# Deploying
echo "Running drush deploy"
ddev drush deploy
