Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dbeaver host command support #5375

Closed
1 task done
kevinquillen opened this issue Sep 24, 2023 · 8 comments
Closed
1 task done

Add dbeaver host command support #5375

kevinquillen opened this issue Sep 24, 2023 · 8 comments

Comments

@kevinquillen
Copy link
Contributor

kevinquillen commented Sep 24, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem?

The dbeaver client is not currently supported by a ddev command.

Describe your solution

Support a ddev dbeaver command that auto connects, saves the connection and puts the connection in the DDEV folder for DBeaver for the current running DDEV project. Assumes db name/user/password are DDEV default.

This builds off of the effort started by @MakerTim.

Add a dbeaver command:

#!/bin/bash

## Description: Open project database in DBeaver.
## Usage: dbeaver
## Example: "ddev dbeaver"

# Note that this example uses $DDEV_HOST_DB_PORT to get the port for the connection
# DBeaver command line options can be viewed here https://dbeaver.com/docs/dbeaver/Command-Line/
# DBeaver can be obtained here https://dbeaver.io

CONNECTION="driver=mysql|user=db|password=db|database=db|host=127.0.0.1|port=${DDEV_HOST_DB_PORT}|name=localhost|savePassword=true|folder=DDEV|openConsole=true"

case $OSTYPE in
  "win*"* | "msys"*)
    '/c/Program Files/DBeaver/dbeaver.exe' -con "$CONNECTION" &
    ;;
  "linux-gnu")
    if [ -f "/mnt/c/Program Files/DBeaver/dbeaver.exe" ]; then
      # wsl2 needs cmd to start the dbeaver
      /mnt/c/Windows/System32/cmd.exe /C 'C:"Program Files"\DBeaver\dbeaver.exe -con '\"$CONNECTION\"'' 2>nul &
    fi
    if [ -f "/snap/bin/dbeaver-ce" ]; then
      "/snap/bin/dbeaver-ce" -con "$CONNECTION" &
    fi
    if [ -f "/snap/bin/dbeaver-ee" ]; then
      "/snap/bin/dbeaver-ee" -con "$CONNECTION" &
    fi
    if [ -f "/snap/bin/dbeaver" ]; then
      "/snap/bin/dbeaver" -con "$CONNECTION" &
    fi
    ;;

  "darwin"*)
    open -a dbeaver.app --args -con $CONNECTION &
    echo "Attempted to launch DBeaver.app"
    ;;
esac

This will:

  • Open DBeaver
  • Create a connection with the local DDEV parameters
  • Save that connection
  • Create a DDEV folder to organize this connection

Running the command will open DBeaver with the SQL console open every time, even after a restart and the published port changes.

Tested on: MacOS Ventura

Needs testing:

  • Verification on Windows 7/10/11 and/or WSL2
  • Verification on Linux (Fedora, Ubuntu, Debian)

I can check Fedora when I am home in two weeks... I don't have a good way to test those OS above otherwise.

image

Describe alternatives

No response

Additional context

No response

@rfay
Copy link
Member

rfay commented Sep 25, 2023

I've reopened #4950. Could you bring it along to completion? We can also just remove the lines that say we support things that we don't have time to test.

@kevinquillen
Copy link
Contributor Author

Updated to make the Linux portion simpler:

#!/bin/bash

## Description: Open project database in DBeaver.
## Usage: dbeaver
## Example: "ddev dbeaver"

# Note that this example uses $DDEV_HOST_DB_PORT to get the port for the connection
# DBeaver command line options can be viewed here https://dbeaver.com/docs/dbeaver/Command-Line/
# DBeaver can be obtained here https://dbeaver.io

CONNECTION="driver=mysql|user=db|password=db|database=db|host=127.0.0.1|port=${DDEV_HOST_DB_PORT}|name=localhost|savePassword=true|folder=DDEV|openConsole=true"

case $OSTYPE in
  "win*"* | "msys"*)
    '/c/Program Files/DBeaver/dbeaver.exe' -con "$CONNECTION" &
    ;;
  "linux-gnu")
    # For WSL2.
    if [ -f "/mnt/c/Program Files/DBeaver/dbeaver.exe" ]; then
      # WSL2 needs cmd to start dbeaver.
      /mnt/c/Windows/System32/cmd.exe /C 'C:"Program Files"\DBeaver\dbeaver.exe -con '\"$CONNECTION\"'' 2>nul &
    fi
    # Check for different editions. Launch the first one found.
    EDITIONS=(dbeaver-ce dbeaver-ee dbeaver)
    for edition in "${EDITIONS[@]}"; do
      if [ -x "$(command -v $edition)" ]; then
        echo "Launching $edition."
        $edition -con "$CONNECTION" &> /dev/null & disown
        exit 0;
      fi
    done
    ;;

  "darwin"*)
    open -a dbeaver.app --args -con $CONNECTION &
    echo "Attempted to launch DBeaver.app"
    ;;
esac

@rfay
Copy link
Member

rfay commented Oct 14, 2023

This was completed in

In the future we can figure out how to add other OSes etc.

@rfay rfay closed this as completed Oct 14, 2023
@Brupes
Copy link
Contributor

Brupes commented Feb 28, 2024

will you keep the work on this? will ddev dbeaver support windows with wsl2?
i use dbeaver for everything and not having the default path (installation to all users) like in heidisql does not help since i use multiple projects at the same time and i do not want to add thousands of connections to my dbeaver.

@Brupes
Copy link
Contributor

Brupes commented Feb 28, 2024

  "linux-gnu")
    # Check for different binaries. Launch the first one found.
    BINARIES=(
      /usr/bin/dbeaver{,-ce,-le,-ue,-ee}
      /var/lib/flatpak/exports/bin/io.dbeaver.DBeaverCommunity
      /snap/bin/dbeaver-ce
      '/mnt/c/Program Files/dbeaver/dbeaver.exe'
    )
    for binary in "${BINARIES[@]}"; do
      if [ -x "$binary" ]; then
        echo "Launching $binary"
        "$binary" -con "$CONNECTION" &> /dev/null & disown
        exit 0
      fi
    done
    ;;

i just tested the script above and it worked for windows with wsl2 and dbeaver community

all i did was to add dbeaver location '/mnt/c/Program Files/dbeaver/dbeaver.exe' and put the call $binary between 2 " so the spaces do not affect it ending with the command "$binary" -con "$CONNECTION"

@rfay
Copy link
Member

rfay commented Feb 28, 2024

Please do a PR if you have a working setup, thanks!

@Brupes
Copy link
Contributor

Brupes commented Feb 29, 2024

i just created a custom command to test it. i didn't compile ddev locally 😅
i can try. just don't know how i can test it but i'll let u know if i was able to do something about this or not

@rfay
Copy link
Member

rfay commented Mar 1, 2024

If you just edit this: https://github.com/ddev/ddev/blob/master/pkg/ddevapp/global_dotddev_assets/commands/host/dbeaver

with your fix, it will offer to create a PR. Then it will automatically build and create artifacts that you can use to test.

See https://ddev.readthedocs.io/en/stable/developers/building-contributing/#testing-a-pr

Would love to have your PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants