Skip to content

fix(api): create the two tables three live features were built on, retire the third route - #741

Merged
thinkclay merged 1 commit into
mainfrom
fix/658-phantom-tables
Sep 10, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/658-phantom-tables

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #658 — and with it the schema half of #660. BASELINE_BROKEN is empty.

Three routers read tables that never existed. The issue said each needed a decision, not a rename. The deciding evidence turned out to be the same question for all three: does anything actually reach this?

core.soft_skills_ratings — created

Four routes, four SDK methods, four hooks, and thirteen components: the profile radar, comparison and history widgets, the rating form, the skills-analytics widgets, the office job-form section, both discover-jobs panes. A whole feature written against a table that was designed and never migrated.

The shape is read off the router, not invented — versioned self-assessments where each PATCH writes max(version)+1, /history reads every version, /comparison reads the latest. Append-only by design, so no UPDATE or DELETE for the user: a corrected assessment is a new version and the old one stays in the timeline.

constraint why
UNIQUE (user_id, skill_id, version) one rating per skill per sitting; all NOT NULL so it genuinely fires (#675)
rating CHECK 1..5 matches the route's zod, so a second writer can't store a 7
FK skill_id → soft_skills RESTRICT the taxonomy retires by is_active, not by delete; history must not lose rows

lib/skill-snapshots.ts, which the issue worried was a second half-built version of the same idea, is not — it's pure arithmetic over core.skill_snapshots, a different and existing table.

core.profile_import_data — created

GET/POST/DELETE, three hooks, ImportReviewScreen at /profile/resume/review, linked from the drawer. One staged import per user awaiting review, with the 24h expiry the route already enforces.

UNIQUE (user_id): the route does delete-then-insert to keep one row, but that pair isn't atomic. The invariant is now the database's — a concurrent second save fails with 23505 instead of leaving two rows for GET's .limit(1).single() to pick between.

core.profile_completion_nudges — not created; the route is retired

One route, one SDK method, one hook — and nothing behind the hook. No component imported useDismissNudgeMutation; the three other "nudge" hits in the tree are prose about application next-steps, a different concept.

It was also never a working upsert: the call named no onConflict target, so with a UUID primary key every "dismiss" would have inserted a fresh row rather than recording one.

Per #660's method, an endpoint no screen can reach does not get a table built for it. Scaffald/sdk#25 retires the method, its types, and its mock-backed test.

RLS follows the house rule for each kind of data

Ratings copy skill_snapshots_select — own rows, or anyone's when that profile's skills are visible. GET /soft takes ?userId= precisely so an employer can view a candidate's, through the request client. (user_skills_select_public has the same intent but compares prefs.user_id to itself — a tautology; the form here is the correct one.)

Staging is own-rows-only for every operation. Never public.

Verified rather than trusted

All against the local stack.

constraints    every CHECK, UNIQUE and FK tried and rejected
live routes    14/14  scripts/audit/test-658.mjs
RLS             5/5   scripts/audit/test-658-rls.mjs — two real sessions via PostgREST
schema guard    6/6   BASELINE_BROKEN empty
deno check      profile-completion.ts 4 → 3 (remainder pre-existing)
typecheck 12/12 · test:unit 8/8 · lint 10/10

The live probe, specifically:

GET /soft                 500 → 200
PATCH /soft               writes v1, then v2 as a NEW version
GET /soft/history         returns both
GET /soft/comparison      200
PATCH rating 9            400
GET /import/data          200 null → POST 201 → GET with expiry
second POST               replaces; exactly one row → DELETE 200
POST /nudges/dismiss      404
GET /completion/status    still 200

The RLS probe uses two real signed-in sessions through PostgREST. My first attempt emulated JWT claims in psql, which is not how auth.uid() reads them — it printed SET for every check, which is not an answer. Worth knowing for the next person.

types.ts regenerated: only additions; application_status still correctly absent (#736).

🤖 Generated with Claude Code

…tire the third route

Closes #658, and with it the schema half of #660: BASELINE_BROKEN is empty.

Three routers read tables that never existed. The issue said each needed a
decision, not a rename, and the deciding evidence was the same question for
all three — does anything reach this?

**core.soft_skills_ratings — created.** Four routes, four SDK methods, four
hooks, and THIRTEEN components: the profile radar, comparison and history
widgets, the rating form, the skills-analytics widgets, the office job-form
section, and both discover-jobs panes. A whole feature written against a table
that was designed and never migrated. The shape is read off the router, not
invented: versioned self-assessments where each PATCH writes max(version)+1,
/history reads every version, /comparison reads the latest. Append-only by
design, so no UPDATE or DELETE for the user — a corrected assessment is a new
version and the old one stays in the timeline. UNIQUE (user_id, skill_id,
version), rating CHECK 1..5 to match the route's zod, FK to core.soft_skills
RESTRICT because the taxonomy retires by is_active, not by delete.

lib/skill-snapshots.ts, which the issue worried was a second half-built version
of the same idea, is not: it is pure arithmetic over core.skill_snapshots, a
different and existing table.

**core.profile_import_data — created.** GET/POST/DELETE, three hooks,
ImportReviewScreen at /profile/resume/review, linked from the drawer. One staged
import per user awaiting review, with the 24h expiry the route already
enforces. UNIQUE (user_id): the route does delete-then-insert to keep one row,
but that pair is not atomic, so the invariant is now the database's — a
concurrent second save fails with 23505 instead of leaving two rows for GET's
.limit(1).single() to pick between.

**core.profile_completion_nudges — NOT created; the route is retired.** One
route, one SDK method, one hook, and nothing behind the hook: no component
imported useDismissNudgeMutation, and the three other "nudge" hits in the tree
are prose about application next-steps. The upsert also named no onConflict
target, so with a UUID primary key every "dismiss" would have inserted a fresh
row — it was never a working upsert. Per #660's method, an endpoint no screen
can reach does not get a table built for it. Scaffald/sdk#25 retires the
method, types and mock-backed test.

RLS follows the house rule for each kind of data. Ratings copy
skill_snapshots_select: own rows, or anyone's when that profile's skills are
visible — GET /soft takes ?userId= precisely so an employer can view a
candidate's, through the request client. (user_skills_select_public has the
same intent and compares prefs.user_id to itself, a tautology; the form here is
the correct one.) Staging is own-rows-only for every operation; it is never
public.

Verified rather than trusted, all against the local stack:

  constraints     every CHECK, UNIQUE and FK tried and rejected (verify354)
  live routes     14/14 — scripts/audit/test-658.mjs
                  GET /soft 500 -> 200; PATCH writes v1 then v2 as a new
                  version; history returns both; comparison 200; rating 9
                  rejected; import GET null -> POST 201 -> GET with expiry
                  -> second POST replaces, exactly one row -> DELETE;
                  nudges/dismiss 404; /completion/status still 200
  RLS             5/5 — scripts/audit/test-658-rls.mjs, through PostgREST
                  with two real sessions, not emulated JWT claims
  schema guard    6/6, BASELINE_BROKEN empty
  deno check      profile-completion.ts 4 errors -> 3 (remainder pre-existing)
  typecheck 12/12  test:unit 8/8  lint 10/10

types.ts regenerated: only additions, application_status still correctly
absent (#736).

SDK pointer: e28fa9c..759b7ec.
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


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.

Three routers are built on tables that were never created

1 participant