pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Add support for overriding DSN connection information

Open A-23187 opened this issue 2 years ago • 4 comments

Description

When connecting using a DSN alias, you can specify additional options (including -h, -p, -u, -W and -d) to override the connection information represented by the DSN you used. For example, pgcli -D dsn -p 54321 means to connect using the alias dsn, while the port is overridden as 54321. It is very useful for me because I have multiple PostgreSQL services deployed on a single server that listen on different ports, I just need to configure only one DSN alias and specify different ports via the -p option to connect to these services.

Checklist

  • [x] I've added this contribution to the changelog.rst.
  • [x] I've added my name to the AUTHORS file (or it's already there).
  • [x] I installed pre-commit hooks (pip install pre-commit && pre-commit install), and ran black on my code.
  • [x] Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

A-23187 avatar Jun 27 '22 17:06 A-23187

Codecov Report

Attention: 237 lines in your changes are missing coverage. Please review.

Comparison is base (6884c29) 84.15% compared to head (90bd5c7) 79.71%. Report is 67 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1352      +/-   ##
==========================================
- Coverage   84.15%   79.71%   -4.45%     
==========================================
  Files          21       25       +4     
  Lines        2720     3036     +316     
==========================================
+ Hits         2289     2420     +131     
- Misses        431      616     +185     
Files Coverage Δ
pgcli/__init__.py 100.00% <100.00%> (ø)
pgcli/completion_refresher.py 91.76% <ø> (+1.17%) :arrow_up:
pgcli/packages/parseutils/__init__.py 100.00% <100.00%> (ø)
pgcli/packages/parseutils/tables.py 97.67% <ø> (ø)
pgcli/packages/prompt_utils.py 70.00% <100.00%> (+5.29%) :arrow_up:
pgcli/packages/sqlcompletion.py 97.67% <ø> (ø)
pgcli/pgstyle.py 64.00% <ø> (ø)
pgcli/magic.py 0.00% <0.00%> (ø)
pgcli/auth.py 91.30% <91.30%> (ø)
pgcli/key_bindings.py 52.94% <66.66%> (-0.19%) :arrow_down:
... and 8 more

... and 1 file with indirect coverage changes

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Jul 22 '22 16:07 codecov-commenter

Specifically, on a test machine, we have many instances of the PostgreSQL service running on random ports (when creating an instance, our administration system randomly selects an available port for that instance), so I can't easily connect to each instance by setting multiple DSN. I hope that when using a DSN whose IP address is set to our test machine to connect, I can specify the port obtained from our administration system with the -p option. But currently pgcli ignore my -p option when I use a DSN to connect, even if this DSN does not explicitly specify a port (if no port is specified, pgcli will use the default port 5432 to connect)

A-23187 avatar Jul 23 '22 12:07 A-23187

our administration system randomly selects an available port for that instance), so I can't easily connect to each instance by setting multiple DSN

@laixintao @A-23187 I agree, this sounds like a valid use case. Are you able to add a test for this, @A-23187 ?

j-bennet avatar Sep 02 '22 16:09 j-bennet

our administration system randomly selects an available port for that instance), so I can't easily connect to each instance by setting multiple DSN

@laixintao @A-23187 I agree, this sounds like a valid use case. Are you able to add a test for this, @A-23187 ?

Sure, I added a script to test this.

A-23187 avatar Jun 02 '23 04:06 A-23187