Skip to content

Implementes TODO in payments-service.ts. convert user admission to postgres stored function#428

Open
Mohit-Davar wants to merge 1 commit intocameri:mainfrom
Mohit-Davar:refactor/admit-user-stored-func
Open

Implementes TODO in payments-service.ts. convert user admission to postgres stored function#428
Mohit-Davar wants to merge 1 commit intocameri:mainfrom
Mohit-Davar:refactor/admit-user-stored-func

Conversation

@Mohit-Davar
Copy link
Copy Markdown
Contributor

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 upsert during the invoice confirmation flow.

  • Added a new Knex migration to provision the admit_user database function, utilizing atomic ON CONFLICT DO UPDATE constraints and preserving ASSERT_SERIALIZED() transaction guarantees.
  • Added corresponding admitUser interface and DB implementations logically grouping this SQL call in UserRepository.

Related Issue

Resolves TODO in payments-service.ts

Motivation and Context

This completes an explicit TODO within 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):

image image

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • All new and existing tests passed.

@phoenix-server
Copy link
Copy Markdown
Collaborator

Created missing issue #435 for this PR. This PR resolves #435.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in PaymentsService.confirmInvoice with userRepository.admitUser(...).
  • Added IUserRepository.admitUser and implemented it via a raw call to the new DB function.
  • Introduced a Knex migration that creates the admit_user PostgreSQL function using INSERT ... 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.

Comment on lines +12 to +17
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();
@cameri cameri linked an issue Apr 10, 2026 that may be closed by this pull request
5 tasks
@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 10, 2026

You will need to rebase to fix your commit messages otherwise commitlint will fail.

@Mohit-Davar
Copy link
Copy Markdown
Contributor Author

Mohit-Davar commented Apr 11, 2026

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.
I’ll rebase my branch and update the commit messages to follow the required convention so CI checks pass. Appreciate the guidance 👍. I will make sure that my future commits will follow this.

@Mohit-Davar Mohit-Davar force-pushed the refactor/admit-user-stored-func branch from ff631b6 to dfe65cc Compare April 11, 2026 07:34
@Mohit-Davar Mohit-Davar force-pushed the refactor/admit-user-stored-func branch from dfe65cc to 0861163 Compare April 11, 2026 07:37
@Mohit-Davar
Copy link
Copy Markdown
Contributor Author

Thanks for pointing this out! I wasn’t aware that Conventional Commits was enforced in this repository. I’ll rebase my branch and update the commit messages to follow the required convention so CI checks pass. Appreciate the guidance 👍. I will make sure that my future commits will follow this.

@cameri I’ve updated all my commits to follow the repository’s commit message conventions and rebased the branch.

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.

Convert user admission to PostgreSQL stored function

4 participants