Skip to content

Commit

Permalink
fix: add restart for database commands after ddev start, fixes ddev#5949
Browse files Browse the repository at this point in the history
  • Loading branch information
stasadev authored Mar 24, 2024
1 parent 77bbe0f commit 96fd091
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/content/users/extend/custom-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ A number of environment variables are provided to these command scripts. These a
* `DDEV_PHP_VERSION`: Current PHP version
* `DDEV_PRIMARY_URL`: Primary project URL
* `DDEV_PROJECT`: Project name, like `d8composer`
* `DDEV_PROJECT_STATUS`: Project status determined from the `web` and `db` services health, like `starting`, `running`, `stopped`, `paused`, or another status returned from Docker, including `healthy`, `unhealthy`, `exited`, `restarting`
* `DDEV_PROJECT_TYPE`: `drupal8`, `typo3`, `backdrop`, `wordpress`, etc.
* `DDEV_ROUTER_HTTP_PORT`: Router port for HTTP
* `DDEV_ROUTER_HTTPS_PORT`: Router port for HTTPS
Expand Down
9 changes: 8 additions & 1 deletion pkg/ddevapp/global_dotddev_assets/commands/host/dbeaver
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
## OSTypes: darwin,linux,wsl2
## HostBinaryExists: /mnt/c/Program Files/dbeaver/dbeaver.exe,/Applications/DBeaver.app,/usr/bin/dbeaver,/usr/bin/dbeaver-ce,/usr/bin/dbeaver-le,/usr/bin/dbeaver-ue,/usr/bin/dbeaver-ee,/var/lib/flatpak/exports/bin/io.dbeaver.DBeaverCommunity,/snap/bin/dbeaver-ce

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi

database="${1:-db}"
Expand Down
9 changes: 8 additions & 1 deletion pkg/ddevapp/global_dotddev_assets/commands/host/heidisql
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@

arguments="--host=\"127.0.0.1\" --port=${DDEV_HOST_DB_PORT} --user=root --password=root --description=${DDEV_SITENAME}"

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi
case $OSTYPE in
"win*"* | "msys"*)
Expand Down
9 changes: 8 additions & 1 deletion pkg/ddevapp/global_dotddev_assets/commands/host/launch
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
## Example: "ddev launch" or "ddev launch /admin/reports/status/php" or "ddev launch phpinfo.php" or "ddev launch https://your.ddev.site" or "ddev launch $DDEV_PRIMARY_URL:3000", for Mailpit "ddev launch -m"
## Flags: [{"Name":"mailpit","Shorthand":"m","Usage":"ddev launch -m launches the mailpit UI"}]

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi
FULLURL=${DDEV_PRIMARY_URL}
HTTPS=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
# Note that this example uses $DDEV_HOST_DB_PORT to get the port for the connection
# Mysql Workbench can be obtained from https://dev.mysql.com/downloads/workbench/

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi
query="root:[email protected]:${DDEV_HOST_DB_PORT}"

Expand Down
10 changes: 8 additions & 2 deletions pkg/ddevapp/global_dotddev_assets/commands/host/querious
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
## HostBinaryExists: /Applications/Querious.app
## DBTypes: mysql,mariadb

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi
DATABASE="${1:-db}"

open "querious://connect/new?host=127.0.0.1&user=db&password=db&use-compression=false&database=${DATABASE}&port=${DDEV_HOST_DB_PORT}"

10 changes: 8 additions & 2 deletions pkg/ddevapp/global_dotddev_assets/commands/host/sequelace
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@

DATABASE="${1:-db}"

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi
query="mysql://root:root@${DDEV_PROJECT}.${DDEV_TLD}:${DDEV_HOST_DB_PORT}/${DATABASE}"

set -x
open "$query" -a "/Applications/Sequel Ace.app/Contents/MacOS/Sequel Ace"

10 changes: 8 additions & 2 deletions pkg/ddevapp/global_dotddev_assets/commands/host/sequelpro
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
## HostBinaryExists: /Applications/Sequel Pro.app
## DBTypes: mysql,mariadb

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi
tmpdir=$(mktemp -d -t sequelpro-XXXXXXXXXX)
templatepath="$tmpdir/sequelpro.spf"
Expand Down Expand Up @@ -79,4 +86,3 @@ cat >$templatepath <<END
END

open "${templatepath}"

9 changes: 8 additions & 1 deletion pkg/ddevapp/global_dotddev_assets/commands/host/tableplus
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
## OSTypes: darwin,wsl2
## HostBinaryExists: /Applications/TablePlus.app,/Applications/Setapp/TablePlus.app,/mnt/c/Program Files/TablePlus/TablePlus.exe

if [ "${DDEV_PROJECT_STATUS}" != "running" ]; then
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
start_exit_code=$?
if [ $start_exit_code -ne 0 ]; then
exit $start_exit_code
fi
# run this script again, as the environment is updated after "ddev start"
no_recursion=true ddev "$(basename "$0")" "$@"
exit $?
fi

dbtype=${DDEV_DBIMAGE%:*}
Expand Down

0 comments on commit 96fd091

Please sign in to comment.