Skip to content

fix(scoring): consolidate duplicate user score fields in schema (#89) - #398

Open
lucky-pluton wants to merge 1 commit into
vicharanashala:mainfrom
lucky-pluton:fix/89-consolidate-score-fields
Open

lucky-pluton wants to merge 1 commit into
vicharanashala:mainfrom
lucky-pluton:fix/89-consolidate-score-fields

Conversation

@lucky-pluton

Copy link
Copy Markdown
Contributor

Closes #89 — Part of the #87 scoring-ledger epic.

TL;DR

The User schema had overlapping/duplicate score fields (\coins\ vs \coinBalance, \xp\ vs \xpScore) that could drift out of sync. This PR consolidates all reads/writes onto canonical \coins\ and \xp\ fields, removes duplicate schema fields and the auto-synchronizing \pre('save')\ hook, and adds an idempotent migration script.

Changes

  • Remove \coinBalance\ and \xpScore\ from \UserSchema\ and \UserStatsSchema\ in \server/auth.js.
  • Remove \pre('save')\ mirroring hook from \UserSchema.
  • Update all call sites (\server/hints/index.js, \server/lil/studentState.js) to read/write canonical \coins\ and \xp.
  • Add \server/scripts/migrate-score-fields.js\ to migrate existing documents without data loss.
  • Add \server/tests/migrateScoreFields.test.js\ unit tests for the migration script.

Verification


  • pm test\ in \server/: all tests passed.

  • px vitest run tests/migrateScoreFields.test.js: 8/8 tests passed.
  • Grep test: \grep -rn 'coinBalance\|xpScore' server/ client/src\ returns no results outside the migration script.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

✅ Parikshak — all automated checks pass

This is Parikshak, an automated, comment-only check — it never closes or approves a PR. A human reviewer still makes the final call. See CONTRIBUTING.md for the full contribution rules.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scoring: consolidate duplicate user score fields in the schema

1 participant