Skip to content

fix(api): five routers addressed tables that do not exist, and one test entry was a phantom - #706

Closed
thinkclay wants to merge 2 commits into
claude/477-api-envfrom
claude/660-schema-refs
Closed

thinkclay wants to merge 2 commits into
claude/477-api-envfrom
claude/660-schema-refs

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Stacked on #704 — review that first. This branch's own diff is the second commit.

Part of #660. The sweep behind #651 left a machine-checkable list: BASELINE_BROKEN in table-references-exist.test.ts, which reads the generated types.ts and needs no database.

32 broken references across 12 table names → 17 across 5.

#656 — the O*NET router addressed the wrong schema entirely

core.onet_occupations and core.onet_skills exist in no schema (confirmed against information_schema). The data lives in onet, keyed on onetsoc_code.

Four occupation reads now select from onet.occupation_data, aliasing onet_code:onetsoc_code so the response shape the SDK consumes is unchanged.

The skills endpoint needed more than a rename. onet.skills is raw O*NET measure data — one row per (onetsoc_code, element_id, scale_id), scale IM being importance and LV level — with no skill name and no category column, where the handler assumed a flat table with both. It now:

  • reads the IM rows,
  • resolves names from onet.content_model_reference in a second query (there is no declared FK, so PostgREST cannot embed it),
  • derives category from the element-id prefix, which is the actual O*NET taxonomy (2.A Basic, 2.B Cross-Functional).

The wire fields importance and category are preserved.

#657 — four wrong-schema references

Each verified against the running database, not only against types.ts:

exists does not exist
public.webhooks core.webhooks
core.job_team_assignments core.team_job_assignments
core.certifications public.certifications
core.user_education public.user_education

The last two carried no .schema() call at all, so they defaulted to public and returned count: null rather than erroring — which is why the university student count silently read 0 for every university instead of failing visibly.

#657's fifth row was not a real defect

office-communities.ts:146 already read .schema("core").from("users"). The test reported it as community.users because its parser buffers to the next semicolon and takes the first .schema() in the statement — and that line sits inside a Promise.all([...]) whose first element is .schema("community"). One statement, two chains, one schema.

The parser now takes the nearest .schema() preceding each .from(). That still catches the office-users.ts delete-cascade bug it was written for — those are separate statements, so each lands in its own buffer and only the first sees a .schema() at all. A regression test covers the multi-chain case, and the phantom entry is removed.

#659 — a 500 where a 404 was already declared

GET /v1/user-profiles/{userId} used .single(). PostgREST answers that with "Cannot coerce the result to a single JSON object" on zero rows, which arrived as an error and was reported as a server fault. A profile that does not exist is an ordinary outcome, and a 500 makes the client retry something that can never succeed. Now .maybeSingle() with an explicit 404; query errors stay separate.

Verified / not verified

Verified: the reference test passes with six entries removed plus the new regression case; deno check over functions/api stays at 411 errors, so none of this adds any.

Not verified: the O*NET tables are empty in the local seed, so the row-level behaviour of the rewritten skills endpoint is unexercised. The shape is checked against information_schema and the generated types; the scale ids come from the O*NET content model rather than from this database. #656's acceptance criterion "returns real rows for a seeded O*NET code" cannot be met until that data is loaded — worth its own issue if the seed is supposed to carry it.

Closes #656
Closes #657
Closes #659

thinkclay and others added 2 commits September 2, 2026 02:05
…st entry was a phantom

Part of #660. The sweep behind #651 left a machine-checkable list —
`BASELINE_BROKEN` in table-references-exist.test.ts, which reads the generated
types.ts and needs no database. It counted 32 broken references across 12 table
names. This takes it to 17 across 5.

**#656 — the O*NET router addressed the wrong schema entirely.** `core
.onet_occupations` and `core.onet_skills` exist in no schema; the data lives in
`onet`, whose key column is `onetsoc_code`, not `onet_code`. Four occupation
reads now select from `onet.occupation_data`, aliasing `onet_code:onetsoc_code`
so the response shape the SDK consumes does not change.

The skills endpoint needed more than a rename. `onet.skills` is raw O*NET
measure data — one row per (onetsoc_code, element_id, scale_id), scale "IM"
being importance and "LV" level — with no skill name and no `category` column,
where the handler assumed a flat table with `importance` and `category`. It now
reads the IM rows, resolves names from `onet.content_model_reference` in a
second query (there is no declared FK, so PostgREST cannot embed it), and
derives `category` from the element-id prefix, which is the actual O*NET
taxonomy. The wire fields `importance` and `category` are preserved.

**#657 — four wrong-schema references,** each verified against the running
database rather than only against types.ts:

    public.webhooks          exists;  core.webhooks              does not
    core.job_team_assignments exists; core.team_job_assignments  does not
    core.certifications      exists;  public.certifications      does not
    core.user_education      exists;  public.user_education      does not

The last two carried no `.schema()` call at all, so they defaulted to public
and returned `count: null` rather than erroring — which is why the university
student count silently read 0 for every university instead of failing.

**#657's fifth row was not a real defect.** office-communities.ts:146 already
read `.schema("core").from("users")`. The test reported it as `community.users`
because its parser buffers to the next semicolon and takes the *first*
`.schema()` in the statement — and that line sits in a `Promise.all([...])`
whose first element is `.schema("community")`. One statement, two chains, one
schema. The parser now takes the nearest `.schema()` *preceding* each
`.from()`, which still catches the office-users.ts delete-cascade bug it was
written for (those are separate statements, so each lands in its own buffer). A
regression test covers the multi-chain case, and the phantom entry is gone.

**#659 — a 500 where a 404 was already declared.** `GET /v1/user-profiles/
{userId}` used `.single()`, and PostgREST answers that with "Cannot coerce the
result to a single JSON object" on zero rows, which arrived as an error and was
reported as a server fault. A profile that does not exist is an ordinary
outcome, and a 500 makes the client retry something that can never succeed.
Now `.maybeSingle()` with an explicit 404, query errors still separate.

Verified: the reference test passes with 6 entries removed and the new
regression case; `deno check` over functions/api stays at 411 errors, so none
of this adds any.

Not verified: the O*NET tables are empty in the local seed, so the row-level
behaviour of the rewritten skills endpoint is unexercised. The shape is checked
against information_schema and the generated types; the scale ids come from the
O*NET content model. #656's "returns real rows for a seeded code" cannot be met
until that data is loaded.

Closes #656
Closes #657
Closes #659

Co-Authored-By: Claude Opus 5 <[email protected]>
…en routes

The reference test fails on unmodified main: routes/moderation.ts reads
core.content_reports and core.user_blocks, and neither is in types.ts. Both
tables exist in the database — #703 shipped their migrations without
regenerating the checked-in types, so the routes are right and the catalogue is
stale.

Regenerating is not the fix and was tried: `supa:generate` against the local
stack adds the three expected objects and also deletes the application_status
enum, which the local database does not have and types.ts does. See #707.

Listed rather than excused, so the count still only goes down — once types.ts is
regenerated these go stale and the test demands their removal.

Refs #707

Co-Authored-By: Claude Opus 5 <[email protected]>
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