fix(merge): carry moves/hints and per-variant best moves on account merge
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 14s
CI / ui (pull_request) Successful in 51s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m18s

The account merge predated the recent statistics additions and silently dropped
them:
- account_stats.moves and hints_used were not summed into the primary (the
  secondary's row is read, then deleted), so the secondary's lifetime moves and
  hints were lost.
- account_best_move was not handled at all; the secondary is only tombstoned
  (not deleted), so its per-variant best moves lingered on the dead account and
  never reached the merged statistics screen.

mergeStats now also sums moves + hints_used; a new mergeBestMoves folds the
secondary's best moves into the primary keeping the higher-scoring play per
variant (the rule the per-game upsert uses), then deletes the secondary's rows.
Profile fields were already correct (hint wallet summed, paid_account ORed; no
new accounts columns since).

Tests: TestAccountMergeCore extended — moves/hints summed, best moves merged
(higher score per variant kept), secondary rows cleaned up. Docs: ARCHITECTURE §4.
This commit is contained in:
Ilia Denisov
2026-06-17 23:56:04 +02:00
parent 6d1d8030e3
commit ed7c6ac56d
3 changed files with 103 additions and 5 deletions
+2 -1
View File
@@ -203,7 +203,8 @@ arrive from a platform rather than completing a mandatory registration).
guest is promoted to durable, clearing `is_guest`).
- **Merge** retires the account that owns the linked identity into the **current**
account, in a single transaction (`internal/accountmerge`): statistics summed
(max points kept), the hint wallet summed, `paid_account` ORed, identities
(counters incl. moves/hints added, max points kept, and the per-variant best moves
merged keeping the higher-scoring play), the hint wallet summed, `paid_account` ORed, identities
repointed, games / chat / complaints transferred, friends and blocks
de-duplicated (friendships keep the strongest status accepted>pending>declined),
pending invitations/codes dropped, and the secondary kept as an **audit