Repository navigation
fix: a table with a composite primary key gets list and create routes only - #267
Conversation
… only Its controller addressed one row by a column named id, which the table does not have: GET, PATCH, PUT and DELETE /:id answered 400, and apso test smoke failed on the create because the response has no id. The routes that address one row are now left out for a composite key, with their MCP tools, the smoke test skips the table with the reason, and the import report says what the API offers (#250).
cultron
left a comment
There was a problem hiding this comment.
Looks good: for a composite key the controller now excludes getOne/updateOne/replaceOne/deleteOne/recoverOne in @crud and drops the matching @OverRide methods, so the OpenAPI contract and the get_/update_/delete_ MCP tools go with them, while list, createOne and createMany stay. A single key is unchanged (compositeKey is only true when keyFields.length > 1). The smoke plan uses the same key rule as the controller and skips the entity with a clear reason before its parents are worked out, so the topological pass reports any child that needs it as skipped instead of failing. The import report line matches the new behaviour, and both the controller and the plan have tests. Nothing must change. At review time build and the credentials scans had passed; auth-smoke, break-each-rule and build-and-publish were still running.
cultron
left a comment
There was a problem hiding this comment.
Looks good: for a composite-key entity the controller now excludes getOne/updateOne/replaceOne/deleteOne/recoverOne in the routes config and drops the matching overrides (and so their MCP tools), while single-key entities are unchanged. The smoke plan skips the entity with a clear reason, and children that require it as a parent already fall through to the existing "skipped entity" path in the topological pass. Tests cover both the composite and single-key controller and the plan skip. Checks are green except break-each-rule (typescript), still running at review time.
- The generated controller spec called controller.get(), which a composite-key controller no longer has, so the service's own tests did not compile. - A key column that references an auth entity was not counted, so such an entity kept one-row routes that matched on part of its key. - The smoke plan skips a composite key for TypeScript only. Python and Go services still declare the routes, so their rows are tried as before.
What this fixes
A table whose primary key is more than one column got a controller that addresses one row by a column named
id. The table has no such column.GET,PATCH,PUTandDELETE /:idanswered 400 withUnknown column 'id' in query.apso test smokefailed for the whole service, because the create response has noid.Listing and creating rows already worked.
The change
For an entity with a composite key:
get_,update_,delete_). List and create stay.apso test smokeskips the entity and prints the reason.apso test accessbuilds on the same plan.An entity with a single key is unchanged.
What this does not do
It does not add routes that address a row by a composite key. That needs a change in
@apso/crud, whose routes are fixed at/:id, and a decision on the URL shape. #250 offers two outcomes: support composite keys, or say clearly what the generated table looks like. This is the second one.Review
An independent review of the first commit found one regression and three older problems. The second commit fixes the regression and two of the three:
controller.get(), so the generated service's own tests did not compile. Fixed.Favoritekeyed by a user and a post kept one-row routes that matched on the post alone, soDELETE /Favorites/7removed the first row for post 7. That predates this PR. Such an entity now counts as a composite key.@apso/crud-typeormstrips primary keys from a create that has a tenant. An API key can. That predates this PR and belongs inapso-packages.How it was checked
mcp: true, on this build.apso test smokepasses and prints the skip. Create and a filtered list work. The four one-row routes answer 404. The controller declares the list and create tools only.apso test smokepasses.npm test: 931 passed, 0 lint errors. Tests cover the controller and its spec for a composite key and a single key, a key through an auth entity, and the smoke plan per language.