Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion completion/bash/itkdev-docker-compose-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _idc_completions()
fi

# Keep the suggestions in a local variable
local suggestions=($(compgen -W "dory:start dory:stop url open drush nfs:enable template:install traefik:start traefik:stop traefik:open traefik:url mail:open mail:url mailhog:open mailhog:url sql:connect sql:log sql:port sql:open xdebug xdebug3 hosts:insert self:update sync sync:db sync:files images:pull composer php version bin/console" -- "${COMP_WORDS[1]}"))
local suggestions=($(compgen -W "dory:start dory:stop url open drush nfs:enable template:install traefik:start traefik:stop traefik:open traefik:url mail:open mail:url mailhog:open mailhog:url sql:cli sql:connect sql:log sql:port sql:open xdebug xdebug3 hosts:insert self:update sync sync:db sync:files images:pull composer php version bin/console" -- "${COMP_WORDS[1]}"))

COMPREPLY=("${suggestions[@]}")

Expand Down
1 change: 1 addition & 0 deletions completion/zsh/_itkdev-docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ _itkdev-docker-compose() {
'sync[Sync both database and files.]' \
'sync\:db[Sync database base.]' \
'sync\:files[Sync files base.]' \
'sql\:cli[Open mysql cli.]' \
'sql\:connect[Print mysql command for connecting to database.]' \
'sql\:log[Log SQL queries sent to database.]' \
'sql\:port[Display the exposed MariaDB SQL server port.]' \
Expand Down
32 changes: 26 additions & 6 deletions scripts/itkdev-docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ Commands:
Sync files base on 'REMOTE_PATH' or 'LOCAL_PATH' in
the env file.

sql:cli
Open MySQL client to the database (named `db`) in the database
container (`mariadb`).

Execute a SQL query from the command line:

itkdev-docker-compose sql:cli --table <<< 'SHOW TABLES'

Run a SQL script:

itkdev-docker-compose sql:cli < query.sql

sql:connect
Print mysql command for connecting to database (named
`db`) in the database container (`mariadb`).
Expand Down Expand Up @@ -564,7 +576,7 @@ case "$cmd" in
fi

if command -v pv >/dev/null 2>&1; then
ssh ${REMOTE_HOST} ${REMOTE_DB_DUMP_CMD} | pv | eval $(itkdev-docker-compose sql:connect)
ssh ${REMOTE_HOST} ${REMOTE_DB_DUMP_CMD} | pv | $script_path sql:cli
else
cat <<EOF
Protip: run
Expand All @@ -573,7 +585,7 @@ Protip: run

to show progress
EOF
ssh ${REMOTE_HOST} ${REMOTE_DB_DUMP_CMD} | eval $(itkdev-docker-compose sql:connect)
ssh ${REMOTE_HOST} ${REMOTE_DB_DUMP_CMD} | $script_path sql:cli
fi

if [ ! -z "${SYNC_DB_POST_SCRIPT:-}" ]; then
Expand Down Expand Up @@ -608,11 +620,19 @@ EOF
eval rsync -avz ${excludes} ${REMOTE_HOST}:${REMOTE_PATH}/ ${docker_compose_dir}/${LOCAL_PATH}
;;

sql:cli)
db_service=mariadb
exec_args=()
# @see https://stackoverflow.com/a/2456870?
if ! [ -t 0 ]; then
exec_args+=("--no-TTY")
fi
docker compose exec "${exec_args[@]}" $db_service mysql --user=db --password=db --database=db "$@"
;;

sql:connect)
address=$(docker_compose port mariadb 3306)
host=$(echo $address | cut -d: -f1)
port=$(echo $address | cut -d: -f2)
echo mysql --host=$host --port=$port --user=db --password=db db
db_service=mariadb
echo docker compose exec $db_service mysql --user=db --password=db db
;;

sql:open)
Expand Down