fix(prompts): restore soft-deleted prompts on upsert match instead of skipping#2583
Open
byteclimber wants to merge 1 commit into
Open
fix(prompts): restore soft-deleted prompts on upsert match instead of skipping#2583byteclimber wants to merge 1 commit into
byteclimber wants to merge 1 commit into
Conversation
… skipping upsertPrompts built its existence lookup without a status filter, so it matched soft-deleted rows, then dropped any soft-deleted match entirely (no insert, no update, no restore). Re-importing an identical prompt silently no-oped while the API still returned 201 with created:0/skipped:N. A brand left with only soft-deleted prompts (e.g. ZEE: 0 active / 817 deleted) could never re-create identical prompts. Replace the skip-on-deleted-match with restore-on-match: a matched row is now updated, which sets status back to 'active' (via row.status, default 'active'), restoring the prompt and refreshing its fields. Inserts still happen only for genuinely new prompts. Updated the two unit tests that previously asserted the silent-skip behavior to assert restore-on-match (update back to active, no insert). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
upsertPrompts(src/support/prompts-storage.js) built its existence lookup without a status filter, so it matched soft-deleted rows — then dropped any soft-deleted match entirely:Re-importing an identical prompt silently no-oped while the API still returned 201 with
created:0 / skipped:N. A brand left with only soft-deleted prompts could never re-create identical prompts — the import dedup matched the deleted ghosts and skipped.Observed in production
Brand
019e92a2-…40(ZEE):GET /prompts→total:0,GET /prompts?status=deleted→total:817. Every re-import returned 201 but wrote nothing. (The 817 rows were restored out-of-band; this PR fixes the cause.)Fix
Replace skip-on-deleted-match with restore-on-match: a matched row now flows into the update path, which sets
statusback to'active'(viarow.status, default'active') and refreshes its fields. Genuinely new prompts still insert. This makes re-import idempotent and self-healing for soft-deleted rows.Tests
active, targeting the existing row by uuid, no insert).prompts-storagesuite passes (124 tests).Risk
Low. Behavior change is confined to the deleted-match branch; the active-match and new-insert paths are unchanged. Restoring updates existing rows rather than inserting, so it cannot create duplicates.
🤖 Generated with Claude Code