feat: add support for searching trial users by external user id - #1869
Conversation
|
This PR will trigger a minor release when merged. |
There was a problem hiding this comment.
Hey @vivesing,
⚠ Degraded review - no spec document was found for this change (searched the PR links, the touched repos docs, the architecture/guidelines docs, and linked Jira). This review covers code-level quality but could not validate the change against an agreed design, so confidence is reduced. Add a spec link (PR template section 4) and re-request review for a full-confidence pass.
Verdict: Approve - clean, mechanical, pattern-following addition with no issues found.
Complexity: LOW - trivial diff; Database/Schema signal.
Changes: Adds a composite index on externalUserId (with updatedAt sort key) to the TrialUser schema and an integration test for the generated findByExternalUserId method (2 files).
Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 0m 56s | Cost: $2.12 | Commit: eb8133428b72b3c505d232a26508f48250422ae3
If this code review was useful, please react with 👍. Otherwise, react with 👎.
calvarezg
left a comment
There was a problem hiding this comment.
Hey @vivesing,
⚠ Degraded review - no spec document was found for this change (searched the PR links, the touched repos' docs, the architecture/guidelines docs, and linked Jira). This review covers code-level quality but could not validate the change against an agreed design, so confidence is reduced. Add a spec link (PR template section 4) and re-request review for a full-confidence pass.
Verdict: Comment - the schema change is correct and pattern-following; one type-declaration gap plus a few non-blocking notes.
Complexity: LOW - trivial diff; Database/Schema signal.
Changes: Adds a composite index on externalUserId (sort key updatedAt) to the TrialUser schema and one IT test for the generated findByExternalUserId (2 files).
Should fix before merge
- [Important] The new index generates
findByExternalUserId/allByExternalUserIdat runtime, butsrc/models/trial-user/index.d.tsdeclares neither - TS consumers of the new accessor get no type signature. The siblingorganizationIdandemailIdindexes both declare their find/all pairs in that file, so this is an incomplete change against the file's own convention. Note: this repo has notsc/type-check step in CI, so the gap does not fail CI here; it surfaces as a compile error in a downstream TypeScript consumer. (details inline)
Non-blocking (3): suggestions and nits
- suggestion:
findByExternalUserIdis a singular accessor over a nullable, non-unique field (theupdatedAtsort key implies one-to-many). On a duplicate or absentexternalUserIdit returns one arbitrary row with no signal. Decide and document whetherexternalUserIdis unique per trial user; if it is not, callers should preferallByExternalUserId. -packages/spacecat-shared-data-access/src/models/trial-user/trial-user.schema.js:57 - nit: the IT test covers only the happy path; add a not-found assertion (
expect(await TrialUser.findByExternalUserId('nonexistent-id')).to.be.null) to pin the not-found contract. -packages/spacecat-shared-data-access/test/it/trial-user/trial-user.test.js:24 - nit: this brings the trial-user schema to 4 indexes against a hard cap of 5 (enforced in
schema.builder.jsat module import, not at deploy) - the next lookup index added will throw at service startup. -packages/spacecat-shared-data-access/src/models/trial-user/trial-user.schema.js:57
Out of scope, worth tracking
- Cross-repo deploy ordering: the physical Postgres index lives upstream in mysticat-data-service (886, merged). Confirm it exists in each environment before consumers call
findByExternalUserId, otherwise lookups fall back to a full table scan. - Authorization for lookup-by-external-id is enforced by the API-service caller, not this library. Confirm the calling route applies the usual access control.
|
@calvarezg , review comments addressed in #1871 |
## [@adobe/spacecat-shared-data-access-v4.19.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.18.0...@adobe/spacecat-shared-data-access-v4.19.0) (2026-08-11) ### Features * add support for searching trial users by external user id ([#1869](#1869)) ([ec48340](ec48340))
|
🎉 This PR is included in version @adobe/spacecat-shared-data-access-v4.19.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
Goal: Expose the newly added
external_user_idDB index (mysticat-data-service) through the JS data-access layer forTrialUser.related to index added in DB https://github.com/adobe/mysticat-data-service/pull/886
Files changed
packages/spacecat-shared-data-access/src/models/trial-user/trial-user.schema.js{ composite: ['externalUserId'] }/{ composite: ['updatedAt'] }packages/spacecat-shared-data-access/test/it/trial-user/trial-user.test.js'gets a trial user by external user id'coveringTrialUser.findByExternalUserId(...)What this generates
The new schema index auto-generates these methods on
TrialUserCollection:findByExternalUserId(externalUserId)allByExternalUserId(externalUserId)findByExternalUserIdAndUpdatedAt(externalUserId, updatedAt)allByExternalUserIdAndUpdatedAt(externalUserId, updatedAt)Test coverage
findByExternalUserId, following the existingfindByEmailId/allByOrganizationIdpattern in the same file.test/it/postgrest/all-collections-methods-coverage.test.jsgenerically sweeps allallBy*/findBy*accessors, so it picks up the new methods without any manual entry.findBy*/allBy*accessors.