From 97836712f2664b87a13904c3f4ef59cea1d99781 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 20 Jul 2024 13:52:19 +0100 Subject: [PATCH] Add `run db` to connect to the database --- templates/php/drupal/.env.example.twig | 4 ++++ templates/php/drupal/run.twig | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/templates/php/drupal/.env.example.twig b/templates/php/drupal/.env.example.twig index 4ce83b2..fddb10f 100644 --- a/templates/php/drupal/.env.example.twig +++ b/templates/php/drupal/.env.example.twig @@ -14,3 +14,7 @@ export DRUSH_OPTIONS_URI="https://${COMPOSE_PROJECT_NAME}.docker.localhost" export MYSQL_DATABASE=app export MYSQL_PASSWORD=app export MYSQL_USER=app + +export DB_NAME="$MYSQL_DATABASE" +export DB_PASSWORD="$MYSQL_PASSWORD" +export DB_USER="$MYSQL_USER" diff --git a/templates/php/drupal/run.twig b/templates/php/drupal/run.twig index 6f866ba..ab2bc51 100755 --- a/templates/php/drupal/run.twig +++ b/templates/php/drupal/run.twig @@ -53,6 +53,13 @@ function composer { _exec php composer "${@}" } +# Connect to the database. +function db { + [[ -f ".env" ]] && source .env + + docker compose exec database mysql -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" +} + function drush { _exec php drush "${@}" }