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 support for overriding DSN connection information #1352

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

A-23187
Copy link

@A-23187 A-23187 commented Jun 27, 2022

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

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

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2022

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%) ⬆️
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%) ⬆️
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%) ⬇️
... and 8 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@laixintao laixintao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer that you set multiple DSN, this feature is kind of hard to explain.

But if @j-bennet or @amjith is ok then I am ok with it.

Can you document this behavior and add some tests?

remap.get(k, k): v
for k, v in kwargs.items()
if ctx.get_parameter_source(k) is click.core.ParameterSource.COMMANDLINE
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add testcases for this part? thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I add a script to test this part, I mock PGCli.connect_uri to verify that whether using -D dsn along with -h -p -u -d -W can override the connection information of dsn. But I'm not familiar with pytest, so let me know if there are any problems in my test script

@A-23187
Copy link
Author

A-23187 commented Jul 23, 2022

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)

@j-bennet
Copy link
Contributor

j-bennet commented Sep 2, 2022

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 ?

@A-23187 A-23187 requested a review from laixintao June 2, 2023 03:58
@A-23187
Copy link
Author

A-23187 commented Jun 2, 2023

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.

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

Successfully merging this pull request may close these issues.

None yet

4 participants