Skip to content

fix(selfhost): translate json_each() array iteration for Postgres - #9383

Merged
JSONbored merged 2 commits into
mainfrom
claude/orb-beta-deploy-b9d67c
Jul 27, 2026
Merged

fix(selfhost): translate json_each() array iteration for Postgres#9383
JSONbored merged 2 commits into
mainfrom
claude/orb-beta-deploy-b9d67c

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Self-host Postgres deployments crash-loop on boot: migrations/0191_linked_issue_claims.sql's backfill iterates a JSON array column with SQLite's json_each(text), which reaches Postgres untranslated (Postgres's own json_each() only accepts JSON objects, so it throws function json_each(text) does not exist).
  • Add a json_each(col) alias -> json_array_elements_text((col)::json) AS alias(value) translation rule in pg-dialect.ts, matching the existing json_extract translation pattern.
  • Verified against a real Postgres 16: ran the full 198-migration chain via runSelfHostMigrations end-to-end, and confirmed the backfill produces correct rows from a JSON array ([7,42] -> two linked_issue_claims rows).

Test plan

  • New regression test in test/unit/selfhost-pg-dialect.test.ts covering both the bare-alias and AS-alias forms, plus the full migration statement
  • npm run typecheck clean
  • Full migration chain run against a throwaway real Postgres 16 (not just unit-level string assertions)
  • Broader test/unit sweep: 766 passed, 0 failures related to this change

migrations/0191_linked_issue_claims.sql's backfill uses SQLite's
json_each(text) to iterate a JSON array column. Untranslated on the
self-host Postgres backend, Postgres's own json_each() only accepts
JSON objects and rejects a text argument outright
("function json_each(text) does not exist"), crash-looping the
migration runner on boot and taking self-host Postgres deployments
down. Add a json_each -> json_array_elements_text translation rule,
verified against a real Postgres 16 running the full migration chain.
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
loopover-ui a633f4a Jul 27 2026, 03:31 PM

@JSONbored JSONbored self-assigned this Jul 27, 2026
@JSONbored
JSONbored merged commit da4b703 into main Jul 27, 2026
4 of 5 checks passed
@JSONbored
JSONbored deleted the claude/orb-beta-deploy-b9d67c branch July 27, 2026 15:42
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.56%. Comparing base (27b44f3) to head (a633f4a).
⚠️ Report is 7 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9383      +/-   ##
==========================================
- Coverage   89.46%   88.56%   -0.91%     
==========================================
  Files         836      836              
  Lines      109590   109591       +1     
  Branches    26098    26098              
==========================================
- Hits        98048    97058     -990     
- Misses      10279    11561    +1282     
+ Partials     1263      972     -291     
Flag Coverage Δ
backend 93.57% <100.00%> (-1.66%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/selfhost/pg-dialect.ts 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant