Borvik / vscode-postgres

PostgreSQL extension for vscode providing explorer, highlighting, diagnostics, and intellisense
MIT License
226 stars 48 forks source link

Automatically connect to specified db #232

Open orrin-naylor-owner-built opened 1 year ago

orrin-naylor-owner-built commented 1 year ago

Hi 👋 It'd be really cool if you could specify a db to automatically connect to. My company has this extension installed by default on our github codespaces dev container. Only issues is you have to re-enter connection creds every time you checkout a new instance. I'd be very nice if we could specify an instance in the workspaces settings.json. That way new developers would be connected to the dev db without having to follow instructions on a readme

bbsimonbb commented 1 year ago

A common convention is to have pg connection details assigned as environment variables (PGUSER, PGPASSWORD, PGDATABASE, PGHOST, PGPORT). These picked up by Node and, for example, pgtyped. Postgresql should use these if present ?

mratanusarkar commented 1 month ago

same requirement. I have a .devcontainer and have configured this extension. now, during container build, I have pulling my secrets and have proper management of .env. I would like auto connect and setup the postgres connection, up and ready during the container built itself! It's annoying to add it manually everytime.

is there any way I can handle the same in .vscode -> settings.json or in the .devcontainer/devcontainer.json -> "customizations" -> "vscode" -> "settings" ??

where does vscode-postgres save the connection details? Maybe we can try to override that to automate this process. some insight would be really helpful!

Borvik commented 1 month ago

The connection details are stored in the ExtensionContext - just where that is precisely differs and is abstracted away by vscode.

Secrets are stored in the SecretStorage provided through the ExtensionContext and ultimately uses the os keyring to securely store them.

As for automatically connecting - there are some settings to help, namely defaultConnection and defaultDatabase

mratanusarkar commented 3 weeks ago

@Borvik that's understandable, and I don't want to gain access or tamper with the ExtensionContext or the SecretStorage. I see the secret JSON file by right-clicking over the connection, and clicking "edit connection".

but instead of tampering with it, a better solution would be to automate the steps we do in the vscode GUI on top, when we click on the + icon in the extension to add a new connection. It collects the strings step by step from the user in the vscode input box that pops up.

As for automatically connecting - there are some settings to help, namely defaultConnection and defaultDatabase

could you please elaborate a bit on this, which files to change and where... so that instead of manually entering the data, how I can let the extension pick those strings from someplace?

This would help me automate during codespace creation and build, where I can read the credentials from a secure location or .env (which I am already doing), and pass those to the extension, so that end of the codespace built, I readily have the connection established and ready to go!

that way, we don't tamper with the vscode or the extension, but simply automate the manual entry of the credentials to the extension.