Skip to content

fix: use user_id/current_score in scoresService bulk queries - #1834

Open
flare-999 wants to merge 3 commits into
LabsCrypt:mainfrom
flare-999:fix/1800-scores-service-columns
Open

flare-999 wants to merge 3 commits into
LabsCrypt:mainfrom
flare-999:fix/1800-scores-service-columns

Conversation

@flare-999

Copy link
Copy Markdown

Overview

updateUserScoresBulk and setAbsoluteUserScoresBulk in backend/src/services/scoresService.ts wrote to scores (borrower, score) and used ON CONFLICT (borrower), but the scores table created by 1771691269865_initial-schema.js has user_id and current_score. Every bulk score update therefore failed with column "borrower" of relation "scores" does not exist, crashing score updates and background reconciliation.

Related Issue

Closes #1800

Changes

  • [MODIFY] backend/src/services/scoresService.ts

    • updateUserScoresBulk: INSERT INTO scores (user_id, current_score) ... ON CONFLICT (user_id), and the conflict branch now clamps scores.current_score + EXCLUDED.current_score - 500.
    • setAbsoluteUserScoresBulk: reconciliation CTE renamed to reconciled_scores (user_id, current_score), inserts into scores (user_id, current_score) with ON CONFLICT (user_id) and sets current_score = EXCLUDED.current_score.
  • [MODIFY] backend/src/services/__tests__/scoresService.test.ts

    • Updated the SQL assertion from ON CONFLICT (borrower) to ON CONFLICT (user_id).
  • [MODIFY] backend/src/__tests__/scoresService.test.ts

    • The DB-backed suite created a legacy scores (borrower, score) fixture; it now creates/reads user_id / current_score so it exercises the real schema.
  • [MODIFY] backend/src/__tests__/migration.test.ts

    • Score insert/select/delete helpers now use user_id / current_score.

Verification Results

Implemented via GitHub Contents/Git API (no local clone).
Acceptance criteria mapping:
The SQL in scoresService.ts now targets user_id / current_score (both bulk functions)
No remaining `borrower` / `score` column references in scoresService.ts
The DB-backed and migration tests were aligned with the real `scores` schema
Acceptance Criteria Status
SQL queries use user_id and current_score updateUserScoresBulk and setAbsoluteUserScoresBulk both updated
ON CONFLICT targets an existing unique column ON CONFLICT (user_id) (unique per initial-schema migration)
No regression in unit assertions scoresService.test.ts expectation updated

@flare-999

Copy link
Copy Markdown
Author

@LabsCrypt both failing checks are green now.

Before: backend, env-docs-check
After: both pass.

Root cause & fix

  • backend failed on the new query() calls in backend/src/services/scoresService.ts because they weren't wrapped the way prettier/prettier requires — reformatted the call sites (no behavioural change).
  • env-docs-check is the env-documentation guard: the branch was behind main, so the documented env vars didn't match the current code. Merging main in brought the branch's docs/code back in sync, and the guard passes.

Head c5da1c941f → 280e4cb97a.

This branch has not been deployed

No deployments
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.

[Bug][Backend] scoresService bulk functions query non-existent columns (borrower, score) crashing on user_id schema

1 participant