Skip to content

refactor(integrations): connections know their integration, ready for a second one - #648

Merged
allisonmahmood merged 2 commits into
mainfrom
refactor/644-integration-aware-connections
Oct 13, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
refactor/644-integration-aware-connections

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Patchy's connection code assumes Postgres throughout:

  • The database only accepts Postgres connections.
  • Two connections can't share a handle, even across integrations.
  • The CLI and SDK look a connection up by handle alone.
  • Deletion protection and the call log's query text only recognise Postgres.

So the PostHog integration (#643) has nowhere to go. This PR is the groundwork. It adds no PostHog code and changes nothing for people using Postgres today.

What changes

  • Naming. A connection is named <integration>/<handle>, such as postgres/warehouse. The CLI takes that name: patchy list connections postgres/warehouse. A bare warehouse still works when only one connection has it. Text output prints the full name.
  • Wire. The API gains GET /connections/:integration/:handle. Older CLIs keep working unchanged:
    • GET /connections stays Postgres-only unless asked for integrations=all.
    • GET /connections/:handle still answers as Postgres.
  • Any integration. These now work for every integration, not just Postgres:
    • Schema snapshots record their integration, so one that outlives its connection still says what it is.
    • Deletion protection finds a declaring version of any integration.
    • The call log keeps query text for any <integration>.query.
    • The portal's per-patch log labels connection calls by full name.
    • Publish binding checks the declaration's integration.

The typed per-integration credential and display variants wait for #646, where PostHog gives them a second case to shape them.

Migrations (hard to roll back). 0011_connections_per_integration and 0012_query_text_any_integration only add or widen, so the release before this one keeps working against the new schema during a rolling deploy or after a rollback:

  • 0011 drops the Postgres-only check and adds the snapshot's integration column, with a 'postgres' default for that release's inserts.
  • Handles stay unique per company for now, which means the same thing while Postgres is the only integration. Connect uses a targetless ON CONFLICT, so it works with either key. feat(integrations): PostHog connections and read-only HogQL for patches #646 swaps in the per-integration key, in one step, and drops the default.
  • 0012 swaps the call log's query-text check for a wider one that still accepts Postgres's writes.

Shown working

  • A new upgrade test in apps/server/src/migrations.test.ts migrates a database that already holds an encrypted connection, its snapshot, a declaring version and a logged query. After the upgrade:
    • everything reads and tests;
    • deletion is still refused;
    • the previous release's exact connection and snapshot inserts still succeed.
  • pnpm check passes.
  • The focused suites pass: integrations, runtime, sdk, portal, the CLI lifecycle and repo tests, and the server's migrations.
  • Neither local pnpm verify run was fully green. Each had a timeout in a test this change doesn't touch, under machine load: packed-CLI init with an empty cache, a PGlite metering test and a company-look publish test. Each passed on the other run or when rerun alone.

Reviewed by GPT 6.1 Sol in Codex. Both of its findings are fixed:

  • The first version dropped what the previous release writes against.
  • The second held two handle keys at once, so concurrent connects could fail on the key their ON CONFLICT didn't name.

Sol also suggested a concurrency test. I didn't add one: a serialized race passes with or without the bug, so it can't guard against it. With a single key and a targetless conflict, the race can't happen.

Closes #644. Part of #643.

Made by Claude Opus 5.5 via Claude Code in T3 Code

… a second one

Every connection path assumed Postgres. A handle is now unique within its
integration and every lookup names the integration. Schema snapshots record
their integration. Deletion protection, the call log's query text and the
portal log labels work for any integration, and the CLI and SDK name
connections as <integration>/<handle>.

The migration only adds: the per-company handle key and the snapshot default
stay for the release before this one, and #646 drops them. Older CLIs keep
today's Postgres-only /connections responses.

Part of #643. Closes #644.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:ui Portal and first-party browser pages, shared rendering and styles size:l 501-1,000 changed lines labels Oct 13, 2026
Holding the per-company and per-integration handle keys together let
concurrent connects fail on the key their ON CONFLICT didn't name. Handles
stay unique per company until #646 swaps the key in one step. Connect uses a
targetless ON CONFLICT, so it works with either key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 0de38f5 into main Oct 13, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the refactor/644-integration-aware-connections branch October 13, 2026 11:02
allisonmahmood added a commit that referenced this pull request Oct 13, 2026
…when Patchy is out of date (#659)

Release 10's What's new entry, written through `64458b2`. It ships as
`patchy` `0.10.0`.

**Changes**
- Fixed: New pages and tools no longer get lost in a temporary folder
(#658)
- Fixed: Your agent hears when its copy of Patchy is out of date (#649,
#654)
- Improved: See a sample tool in your look before you approve it (#656)
- Improved: Publishing the company look says who it's for (#655)

**Behind the scenes**
- Connections to your company's data now record what kind of service
each one reaches (#648)

**No line:** #642, a rename of the glossary docs.

This is the first release with its own version number. After it deploys,
global CLIs from earlier deploys (all `0.0.1`) are refused on file
publish, `init` and `look publish` with the installer line. Patch repos
are told to `pnpm patchy refresh`, as on any release.

Made by Claude Opus 5.5 via Claude Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(integrations): connections know their integration, ready for a second one

1 participant