Implementes TODO in payments-service.ts. convert user admission to postgres stored function#428
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the invoice-confirmation “user admission” workflow to use a PostgreSQL stored function (admit_user) instead of performing an application-layer upsert, centralizing the mutation in the database under serializable transaction guarantees.
Changes:
- Replaced the inline
userRepository.upsert(...)admission logic inPaymentsService.confirmInvoicewithuserRepository.admitUser(...). - Added
IUserRepository.admitUserand implemented it via a raw call to the new DB function. - Introduced a Knex migration that creates the
admit_userPostgreSQL function usingINSERT ... ON CONFLICT DO UPDATE.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/services/payments-service.ts | Switches invoice-confirmation admission step from upsert to stored-function call. |
| src/repositories/user-repository.ts | Adds admitUser repository method that invokes admit_user via Knex raw. |
| src/@types/repositories.ts | Extends IUserRepository interface with admitUser. |
| migrations/20260409201624_admit_user_func.js | Adds migration creating the admit_user PL/pgSQL function for atomic admission upsert. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VALUES (user_pubkey, true, tos_accepted, now_utc(), now_utc()) | ||
| ON CONFLICT ("pubkey") | ||
| DO UPDATE SET | ||
| "is_admitted" = true, | ||
| "tos_accepted_at" = tos_accepted, | ||
| "updated_at" = now_utc(); |
|
You will need to rebase to fix your commit messages otherwise commitlint will fail. |
Thanks for pointing this out! I wasn’t aware that Conventional Commits was enforced in this repository. |
ff631b6 to
dfe65cc
Compare
dfe65cc to
0861163
Compare
@cameri I’ve updated all my commits to follow the repository’s commit message conventions and rebased the branch. |
refactor(db): convert user admission to postgres stored function
Description
This PR refactors the user admission workflow by introducing a PostgreSQL stored function to replace the application-layer
upsertduring the invoice confirmation flow.admit_userdatabase function, utilizing atomicON CONFLICT DO UPDATEconstraints and preservingASSERT_SERIALIZED()transaction guarantees.admitUserinterface and DB implementations logically grouping this SQL call inUserRepository.Related Issue
Resolves TODO in payments-service.ts
Motivation and Context
This completes an explicit
TODOwithin the codebase. Offloading the user admission mutation to a PostgreSQL stored function strengthens the concurrency model .How Has This Been Tested?
Verified existing repository tests pass correctly locally.
Screenshots (if appropriate):
Types of changes
Checklist: