fourkitchens / pantheon-tools

Tools to run actions against a Pantheon site
GNU General Public License v3.0
16 stars 3 forks source link

fix(16): Gracefully handle when Pantheon doesn't tell us the name of the DB #17

Closed dalin- closed 1 year ago

dalin- commented 1 year ago

Running commands like

pantheon-db-cli eam-d8 live
pantheon-db-dump columbia-sps test | gzip > columbia-sps.mysql.gzip

Will now work.

cbfannin commented 1 year ago

@dalin- I keep getting /pantheon-tools/pantheon-db-cli: line 45: mysql: command not found when running pantheon-db-cli eam-d8 live

pantheon-db-dump columbia-sps test | gzip > columbia-sps.mysql.gzip worked great!

dalin- commented 1 year ago

@cbfannin That suggests that on your local machine you have the application mysqldump, but not mysql. Is that correct? If so, any idea how? We might add checks at the top of these files to confirm that you have the required application installed, but that should be a different PR.

cbfannin commented 1 year ago

@dalin- That probably explains my errors. I actually don't have mysql or mysqldump installed on my local machine. I've not had to do anything outside of lando for several months so haven't installed it.

On a Drupal build script I created at my previous employer my co-worker did a basic loop that checked multiple applications to see if they were installed. Maybe something like this will work?

# Functions
isInstalled() {
    # check if command exists and fail otherwise
    command -v "$1" >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        echo "${white}${red} $1 is not installed. ${reset}${white}${red}"
        exit 1
    fi
}
echo "${white}${blue} Checking Prerequisites... ${reset}${white}${blue}"

# Check for required Applications.
for app in "php" "composer" "git" "docker" "lando" "curl"; do
    isInstalled "${app}"
done
dalin- commented 1 year ago

@cbfannin Yes. Something like that. Not sure if the loop is overkill since we only need to check for one application. But let's do that as a separate PR.