Repository navigation
fix(puzzles): assign legacyId to admin-authored puzzles (#2185) - #2220
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Puzzleswas missing from both legacyId assigners inadmin-service.jsand fromgetNextLegacyId'sVALID_ENTITIES, and noPUZZLESHANA sequence existed. Puzzles are@odata.draft.enabled, sobefore CREATEnever 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:PUZZLETaskRecords were written withtaskLegacyId = NULL.srv/lib/user-progress.jsjoins Puzzles bylegacyId, so these rows are silently dropped from My Completions.taskLegacyId: NULL, so the idempotency guard inpuzzle-service.jsconflates distinct puzzles.Fix (mirrors #436)
srv/lib/legacy-id.js— addPuzzlestoVALID_ENTITIES.srv/admin-service.js— addPuzzlesto 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/.hdiconfigalready present).test/hybrid/hana-sequences.test.js— coverPuzzles.Retroactive backfill (12 orphaned PROD records)
scripts/backfill-puzzle-legacyids.mjs— idempotent, dry-run by default. Assigns alegacyIdto every NULL-legacyId puzzle, then relinks orphanedPUZZLETaskRecords (taskLegacyId IS NULL) by matchingtitleSnapshot === 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. ✅