Skip to content

feat(integrations): the Postgres integration: read-only execution, the generated surface and its fixture #202

Closed

Description

@allisonmahmood

Part of #193. Implements spec §6's execution, generated surface, type mapping, errors, bounds and fixture; decision The integration definition, the Postgres integration and its fixture §§ Read-only, The generated surface, Errors, The wire, Bounds and pools, The fixture, The call log; with Dev is local.

What to build

  • In packages/api: postgres.list, get, getMany, query request and response schemas and the codes relation_unknown, invalid_query, shape_mismatch, invalid_cursor, offset_exhausted; responses { ok: true, rows }, no rowCount, no truncated; a call past 1,000 rows or 8 MB fails during collection.
  • Execution: one statement over the extended protocol inside BEGIN READ ONLY with SET LOCAL statement_timeout (10 s), rolled back, session reset; a 15 s service deadline including queue wait that cancels and destroys the connection; pools keyed by connection id and credential revision (4 per connection per process, idle 60 s, 64 per process), the revision checked at checkout so rotate, retarget and disconnect take effect at once while in-flight calls finish. Handlers registered into the runtime handler map; the alias resolved through the loaded version's manifest to the connection id; projection and validation through the snapshot revision the version names, credentials and access live; every call, denied and failed included, logged with the SQL text for query.
  • The type mapping of spec §6 as one module driving the generated types, the projection SQL and the runtime validation (int8 and numeric as strings; NaN and infinities refused; timestamps and dates as specified; domains resolved; unsupported types left out and named).
  • generate(declaration, snapshot): the per-connection client exposing relations directly (public at the top, other schemas namespaced, bracketed when not dottable, query reserved, collisions excluded and named), get and getMany only on relations with a usable primary key, list({ eq, range, orderBy, select, limit, cursor }) with keyset cursors bound to connection, relation, revision, filters and order on keyed relations and a bounded offset (10,000, offset_exhausted) on unkeyed views, view columns nullable, never SELECT *; the context file (handle, description, schema listing, exclusions, keyed relations, revision); discovered names escaped in TypeScript, SQL and markdown. query(sql, params, shape) strict as spec §6 says. Generated error unions per method and isPatchyError.
  • dev(snapshot, fixture): one PGlite per connection under .patchy/dev/, built from the snapshot with source-native types, rows loaded from fixtures/postgres-<handle>.sql on the privileged init path and validated, the stub's header listing tables and columns and saying views are synthetic; a relation the fixture cannot represent excluded from both surfaces and named; raw SQL using what PGlite lacks fails locally with the reason.
  • The recent-calls list per connection on /company/connections from the runtime log.

Admitted at merge

postgres.* operations run for declared connections through the runtime.

Done when

  • query with INSERT fails inside the read-only transaction; a function with a side effect does too; a statement past 10 s is timeout and the connection is destroyed; a rotated credential is used by the next call and never by an in-flight one after its deadline.
  • list with eq, range, orderBy, select and a cursor generates quoted SQL and validated rows for every kind in the mapping; an unkeyed view pages by offset to the bound then offset_exhausted; a relation without a key has no get; a call after the admin's refresh schema still projects through the version's own revision; a dropped source column fails that call with a clear code.
  • query refuses a missing column, a duplicate name and a null in a non-optional column with shape_mismatch; the fixture layer answers the same list from an agent-authored file and names an excluded relation.
  • Every call has a log row with the SQL for query and none for list; the recent-calls list renders it.

Surfaces

The wire, vocabulary (Relation, Escape hatch, Dev binding, Fixture), docs/product.md § What patch code sees and § Development, served pages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions