Skip to content

Commit a6f795e

Browse files
committed
Replace openapi output-schema migration script with a drizzle SQL migration
The envelope unwrap is mechanical jsonb surgery, so it belongs in the regular migration chain (db:migrate:prod) rather than a hand-run script: - 0002_unwrap_openapi_output_envelope.sql rewrites envelope-shaped openapi tool output schemas to the payload schema (NULL when the envelope carried an empty data schema), using structural jsonb comparisons casted from the json column. Rows produced before the envelope existed don't match the predicates; re-running is a no-op.
1 parent aa7f7b4 commit a6f795e

5 files changed

Lines changed: 1250 additions & 108 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Unwrap the retired {status, headers, data} transport envelope from
2+
-- persisted OpenAPI tool output schemas. The runtime now returns the
3+
-- upstream payload as `data` (status/headers moved to the ToolResult
4+
-- `http` side channel), so persisted schemas must describe the payload
5+
-- only. Rows produced before the envelope existed (pre-#854) are already
6+
-- payload-shaped and don't match the predicates; re-running is a no-op.
7+
--
8+
-- The old producer emitted `"data": {}` when an operation declared no
9+
-- response schema; the new producer persists NULL for those.
10+
--
11+
-- output_schema is a `json` column, so structural comparisons cast to
12+
-- jsonb (json has no equality operator).
13+
UPDATE "tool"
14+
SET "output_schema" = CASE
15+
WHEN ("output_schema" -> 'properties' -> 'data')::jsonb = '{}'::jsonb THEN NULL
16+
ELSE "output_schema" -> 'properties' -> 'data'
17+
END
18+
WHERE "plugin_id" = 'openapi'
19+
AND "output_schema" IS NOT NULL
20+
AND "output_schema" ->> 'type' = 'object'
21+
AND ("output_schema" -> 'required')::jsonb = '["status", "headers", "data"]'::jsonb
22+
AND ("output_schema" -> 'properties' -> 'status')::jsonb = '{"type": "integer"}'::jsonb
23+
AND ("output_schema" -> 'properties' -> 'headers')::jsonb = '{"type": "object", "additionalProperties": {"type": "string"}}'::jsonb;

0 commit comments

Comments
 (0)