Skip to content

fix(db): disable useDefineForClassFields so entity updates stay updates#206

Merged
TaprootFreak merged 1 commit into
developfrom
fix/use-define-for-class-fields
Jul 16, 2026
Merged

fix(db): disable useDefineForClassFields so entity updates stay updates#206
TaprootFreak merged 1 commit into
developfrom
fix/use-define-for-class-fields

Conversation

@Danswar

@Danswar Danswar commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Root-cause fix for #205 (the data cleanup follow-up stays tracked there).

What

One line in tsconfig.json"useDefineForClassFields": false — plus a regression spec that pins the semantics.

Why

Commit e18f05a (#84) bumped target from es2017 to es2022, which silently flips TypeScript's useDefineForClassFields default to true. Since then, every entity produced by repo.create() / new Entity() carries all declared columns — including id — as own properties initialized to undefined. The update helpers merge with Object.assign(dbEntity, freshEntity), which copies id: undefined onto the loaded row, so save() issues an INSERT instead of an UPDATE:

  • transaction_onchain has UNIQUE ("transaction") → the 02:00 nightly sync has aborted with UQ_8a233973 duplicate-key errors every night since 2025-11-11 (verified in Loki: 55 dup-key errors/night on PRD, 3/night on DEV — exactly the table row counts — and zero syncOnchainTransactions: runtime= success lines in 30 days).
  • transaction_lightning has no unique constraint → the same pattern silently inserts duplicate rows: the 03:00 sync's entries= count compounded 369 → 1250/night over the last week, and websocket state transitions create new rows instead of updating.

Setting the flag back to Set semantics restores exactly the behavior the codebase ran with before November and fixes all four Object.assign-merge sites at once (lightning-transaction.service.ts ×2, lightning-wallet.service.ts, user-boltcard.service.ts).

Verification

  • Regression spec fails on the unfixed tsconfig (row id gets wiped to undefined) and passes with the fix; ts-jest compiles specs with the repo tsconfig, so it also guards against a future re-flip.
  • npm run build, npm run test (30/30), npm run lint all green locally.
  • After deploy: the nightly Error during processSyncOnchainTransactions should disappear and a syncOnchainTransactions: runtime= line should appear; transaction_lightning should stop growing at the sync rate.

Not in this PR

The es2022 target bump (e18f05a) flipped useDefineForClassFields to
true, so entities from repo.create() carry every declared column as an
own undefined property. The Object.assign(dbEntity, freshEntity) update
pattern then wipes the loaded row's id and save() inserts a duplicate
row instead of updating. Restores the pre-bump Set semantics and pins
them with a regression spec. Root cause of #205.
@Danswar Danswar requested a review from TaprootFreak July 15, 2026 13:38

@TaprootFreak TaprootFreak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed: explicitly disabling define-style class fields restores the pre-ES2022 entity semantics across all affected Object.assign update paths, and the regression test pins both the own-property and preserved-id behavior. CI is green. The required duplicate-row cleanup remains tracked in #205, now assigned to Danswar: #205.

@TaprootFreak TaprootFreak merged commit 5f60e1c into develop Jul 16, 2026
1 check passed
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.

2 participants