Skip to content

[Backend] scores table has no CHECK constraint enforcing the 300-850 range the app clamps in SQL #1197

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

src/services/scoresService.ts:43 clamps with LEAST(850, GREATEST(300, ...)) in application SQL, but the scores table (migrations/1771691269865_initial-schema.js:15 and the ensure-core-tables CREATE branch 1789000000000:10-15) defines the score column as plain integer with no CHECK, so any code path or manual write can persist out-of-range scores. The valid bounds are fixed (loanConfig.ts:13 LOAN_MIN_SCORE_RANGE = {min:300,max:850}).

Acceptance criteria

  • Add a CHECK constraint (score BETWEEN 300 AND 850) on the scores table via migration
  • Backfill/clamp any existing out-of-range rows before adding the constraint

Files to touch

  • backend/migrations/1771691269865_initial-schema.js
  • backend/src/services/scoresService.ts

Out of scope

  • Changing the score range itself

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendIssues related to backend developmentdatabaseDatabase related issuesenhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions