Skip to content

fix(puzzles): assign legacyId to admin-authored puzzles (#2185) - #2220

Merged
jung-thomas merged 1 commit into
DEVfrom
fix/puzzle-legacyid-2185
Sep 9, 2026
Merged

jung-thomas merged 1 commit into
DEVfrom
fix/puzzle-legacyid-2185

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Problem (#2185)

Puzzles can be submitted (Check/Submit → confetti) but their completions never appear in My Completions, and no Devtoberfest points are awarded.

Root cause (confirmed against live DEV + PROD data)

Admin-authored puzzles were saved with a NULL legacyId. Puzzles was missing from both legacyId assigners in admin-service.js and from getNextLegacyId's VALID_ENTITIES, and no PUZZLES HANA sequence existed. Puzzles are @odata.draft.enabled, so before CREATE never fires on the NEW→PATCH→draftActivate flow — the exact bug #436 fixed for Missions/Groups/CompletionPaths, never extended to Puzzles.

Downstream effects of the NULL legacyId:

  • PUZZLE TaskRecords were written with taskLegacyId = NULL.
  • srv/lib/user-progress.js joins Puzzles by legacyId, so these rows are silently dropped from My Completions.
  • The Devtoberfest points path reads the same result (keyed off slug) → no points.
  • Latent collision: every NULL-legacyId puzzle shares taskLegacyId: NULL, so the idempotency guard in puzzle-service.js conflates distinct puzzles.

Fix (mirrors #436)

  • srv/lib/legacy-id.js — add Puzzles to VALID_ENTITIES.
  • srv/admin-service.js — add Puzzles to the CREATE assigner and the NEW/PATCH/SAVE draft self-heal loop.
  • db/src/COM_SAP_DEVELOPERS_IMS_PUZZLES_SEQ.hdbsequence — new sequence (matches sibling pattern; db/src/.hdiconfig already present).
  • test/hybrid/hana-sequences.test.js — cover Puzzles.

Retroactive backfill (12 orphaned PROD records)

scripts/backfill-puzzle-legacyids.mjs — idempotent, dry-run by default. Assigns a legacyId to every NULL-legacyId puzzle, then relinks orphaned PUZZLE TaskRecords (taskLegacyId IS NULL) by matching titleSnapshot === puzzle.title; skips ambiguous/no-match. Run after this deploys (so the sequence exists in HANA):

```bash
cds bind --exec --profile hybrid-prod -- node scripts/backfill-puzzle-legacyids.mjs # dry run
cds bind --exec --profile hybrid-prod -- node scripts/backfill-puzzle-legacyids.mjs --apply # write
```

Tests

  • test/puzzle-legacyid.test.js (new) — draft NEW → draftActivate assigns a non-null numeric legacyId. ✅
  • test/unit/user-progress.test.js — 24 passed (PUZZLE inclusion in My Completions). ✅
  • npx cds deploy --to sqlite::memory: — compiles clean. ✅

Admin-created puzzles were saved with a NULL legacyId because Puzzles was
missing from both legacyId assigners in admin-service.js and from
getNextLegacyId's VALID_ENTITIES, and no PUZZLES sequence existed. Their
PUZZLE TaskRecords were then written with taskLegacyId=NULL and silently
dropped from My Completions (srv/lib/user-progress.js) and the Devtoberfest
points path (same read path, keyed off slug).

Fix mirrors the #436 draft-lifecycle self-heal:
- add Puzzles to VALID_ENTITIES (srv/lib/legacy-id.js)
- add Puzzles to the CREATE assigner and the NEW/PATCH/SAVE draft self-heal
  loop (srv/admin-service.js)
- add COM_SAP_DEVELOPERS_IMS_PUZZLES_SEQ.hdbsequence
- cover Puzzles in the HANA-sequence hybrid test

Adds test/puzzle-legacyid.test.js (draft NEW -> draftActivate assigns a
non-null numeric legacyId) and scripts/backfill-puzzle-legacyids.mjs, an
idempotent dry-run-by-default backfill for the existing orphaned PROD
records (assign legacyId, relink NULL-taskLegacyId PUZZLE records by
titleSnapshot; skips ambiguous/no-match).
@jung-thomas
jung-thomas merged commit efce740 into DEV Sep 9, 2026
6 checks passed
@jung-thomas
jung-thomas deleted the fix/puzzle-legacyid-2185 branch September 9, 2026 15:12
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.

1 participant