Repository navigation
Closed
Labels
Description
Problem
Most of what this issue first asked for has shipped:
- Pre-Connect Script in the connection's Options tab runs through
/bin/bashbefore connecting, and a non-zero exit aborts the connect (connections/connection-form.mdx:73, from feat: add ~/.pgpass file support and pre-connect script #279). - A failure reports the exit code and stderr,
Pre-connect script failed (exit N): ...(apple/TablePro/Core/Services/Infrastructure/PreConnectHookRunner.swift:20-27). - The script never runs unprompted. An alert shows it and waits for Run Script on every connect, whatever started it (
connections/connection-form.mdx:91-93, from fix(connections): ask before any caller runs a pre-connect script #3381), and links, exports and the Team Library do not carry it. - A long-running port forward has its own transport, Tunnel Command, which starts on connect and stops on disconnect (
connections/tunnel-command.mdx).
Three gaps remain:
- The script gets TablePro's environment and nothing about the connection.
runPreConnectScriptIfNeededcallsPreConnectHookRunner.run(script:)with no environment (apple/TablePro/Core/Database/DatabaseManager+Sessions.swift:289), although the runner accepts one (PreConnectHookRunner.swift:38-52). A script shared by several connections has to hardcode each one's host and user. - The timeout is fixed at 10 seconds (
PreConnectHookRunner.swift:70-75). A VPN that takes 15 seconds to come up, or anaws sso loginthat opens a browser, fails every time. - Nothing runs after a disconnect, so whatever the script started (a VPN profile, a credential refresh loop) is left running.
Proposed solution
- Run the pre-connect script with
TABLEPRO_CONNECTION_NAME,TABLEPRO_HOST,TABLEPRO_PORT,TABLEPRO_USERandTABLEPRO_DATABASEin its environment. Never the password. - A timeout field beside the script, 10 seconds by default, up to 300.
- A Post-Disconnect Script, run after the session closes, whether by Disconnect, closing the window or quitting. It runs only for a session whose pre-connect script ran, under the same consent rules, and its failure is logged rather than shown as an error.
Done when: a pre-connect script that prints $TABLEPRO_HOST shows the connection's host, a 30 second timeout lets a slow script finish, and a post-disconnect script runs once per approved session.
Alternatives considered
Hardcode the host in each connection's script, wrap the slow step in a background job, and run the cleanup by hand in Terminal.
Platform
macOS
Related database type
N/A / General
Activity
[-]Run a shell command before and after connecting[/-][+]Pass connection details to the pre-connect script, and add a post-disconnect script[/+]