Conversation
5a3b5a4 to
de6d815
Compare
de6d815 to
9cbeaf0
Compare
|
Thanks for picking up #124! The write side looks right: one shared timestamp, both delete paths covered, and the Blocking1. The soft-delete never shows up for usersNothing that reads reports filters on
Please add 2. Add a CosmosDB index for the new
|
Cedric Vidal (cedricvidal)
left a comment
There was a problem hiding this comment.
Thanks for picking up #124! The write side looks right: one shared timestamp, both delete paths covered, and the deletedAt: { $exists: false } guard keeps existing timestamps intact.
Blocking
1. The soft-delete never shows up for users
Nothing that reads reports filters on deletedAt, so reports for deleted runs are still returned everywhere:
GET /api/v1/reports?projectId=(the top-level list, which is the main thing #124 is about)GET /api/v1/reports?requestId=,GET /reports/:id,GET /reports/:id/logs,GET /reports/:id/insightsPOST /reports/bulk-statusand thebulk-summary$matchGET /insights/:id/reports
Please add deletedAt: { $exists: false } to these reads, plus tests showing deleted reports are left out.
2. Add a CosmosDB index for the new deletedAt filter
Once report reads filter on deletedAt, reports needs a deletedAt index the way the other soft-deleted collections have one. Right now it only has { createdAt: -1 } and { requestId: 1 } (migration 002) plus { projectId: 1 } (025).
Please follow the existing soft-delete index pattern:
- Add a new migration, e.g.
packages/db-migrations/src/migrations/031-add-reports-soft-delete-index.ts, modeled on030-create-resource-indexes.ts:Use theawait ensureIndex(db.collection("reports"), { deletedAt: 1 }, {}, "reports", TAG);
ensureIndexhelper fromcosmos-index-helpers.ts, as migrations 025 and 030 do forprojectsandresources, with adown()that only logs instead of dropping the index. - Register it in
packages/db-migrations/src/required-migrations.ts, or the API readiness probe won't check that it has been applied. - Use single-field indexes: Cosmos combines them for
{ projectId | requestId, deletedAt }filters, and the existing range index oncreatedAtalready handles thecreatedAtsort. If a query ever sorts on a field that only has a unique index, use a two-field compound like{ deletedAt: 1, id: 1 }from migration 024 (#1192). - Add the migration to the table in
docs/architecture/db-migrations.md. - Ideally, check it on the shared dev Cosmos instance (
docs/shared-dev-infra.md) withgetIndexes(), because Cosmos can drop an index without reporting an error.
Should fix
- No test for the bulk path. Add a
DELETE /api/v1/requests/bulktest that checks thereportCollection.updateManycascade is called with only the ids that were actually deleted (existingIds), and not called when nothing matched. - New reports can still be created for deleted runs.
POST /reports,/reports/trigger,/reports/bulk-createand/reports/bulk-triggerlook up runs without filtering out deleted ones. This was already the case before the PR, but it goes hand in hand with the cascade.
Nit
In DELETE /requests/:id, if the report update fails after the run is deleted, retrying gets a 410 and the reports are never cascaded. The cascade is idempotent, so you could also run it in the 410 branch.
Signed-off-by: mnkj0021 <98058999+mnkj0021@users.noreply.github.com>
|
Cedric Vidal (@cedricvidal) I addressed the review feedback across the branch and pushed the final follow-up in 20425ed.
Validation: 183/183 targeted API + migration tests pass; OpenAPI contract tests and snapshot pass; shared, db-migrations, and api TypeScript builds pass; git diff --check passes. I did not run the optional shared-dev Cosmos getIndexes() check from this environment. |
Signed-off-by: mnkj0021 <mnkj.0021@gmail.com>
|
Thanks for the detailed review. I addressed the blocking items and the should-fix/nit follow-ups on the current branch:
Fresh validation on the current branch:
Latest cleanup commit: 4260969. |
|
Give me a bit of time to validate this one, anything touching the DB needs more care. Have you been able to validate this works with CosmosDB or just MongoDB? There are some subtle differences that can bite. |
|
I have not validated this against a real CosmosDB instance yet; the completed validation so far is local/unit/API coverage rather than shared-dev Cosmos. For the index path, migration 031 deliberately uses the existing Cosmos-safe ensureIndex() helper with a single-field { deletedAt: 1 } index, matching the pattern used by migrations 025/030. The new queries also stay within the existing single-field-index model you called out rather than introducing a new compound/sort assumption. I do not have the repo shared-dev Cosmos credentials/environment available on this runner, so I do not want to claim Cosmos validation I have not performed. I will leave the branch unchanged while you validate it rather than churn a DB-sensitive PR. |
Fixes #124
Summary
deletedAtin the report type/schema for persisted soft-delete stateValidation
corepack pnpm --filter shared build— passed on a fresh recheckcorepack pnpm --filter api build— passed on a fresh recheckcorepack pnpm exec vitest run apps/api/src/endpoints.test.ts— 161/161 passedgit diff --check— passedmain(0 commits behind)GitHub's upstream CI workflows are still in
action_requiredand need a Scope maintainer to approve the fork workflow run. The Microsoft CLA check passes.