fix: allow reusing a soft-deleted event's name - #215
Merged
Conversation
Event names were permanently unreusable once soft-deleted: the DB-level unique index on (user_id, name) and the validation rules backing it both ignored deleted_at, so recreating an event with a previously deleted name was rejected forever even though the app has no restore path and the old event is invisible everywhere. - Scope the events unique index to non-deleted rows via a partial index (portable across SQLite and PostgreSQL). - Add withoutTrashed() to the name uniqueness validation in both the web and API EventControllers so validation matches the new constraint. Fixes #83 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E1dCNHSzn1JyxZbZ147TJw
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.
What was broken
EventusesSoftDeletes, and theeventstable has a plain (non-partial) unique index on(user_id, name). That index, and theRule::unique('events', 'name')validation backing it in both the web and APIEventControllers, did not exclude soft-deleted rows.Repro: create an event named
order.created→ soft-delete it → try to create a new event namedorder.createdagain → rejected as "has already been taken," permanently — even though the original event no longer appears anywhere in the UI or API and there is no restore path in the app. For a resource that's literally named by the user (order.created,user.signup, etc.), this is a real, permanent dead end with no workaround short of picking a different name forever.What changed
events(user_id, name)and replaces it with a partial unique index (WHERE deleted_at IS NULL), so the DB-level constraint only applies to non-deleted rows. This raw-SQL syntax is supported identically by SQLite (used in tests) and PostgreSQL (production), so no driver branching is needed.->withoutTrashed()to thenameuniqueness validation rule inapp/Http/Controllers/EventController.php(webstore/update) andapp/Http/Controllers/Api/EventController.php(APIstore/update), so validation now matches the new DB constraint instead of rejecting a request the database would otherwise accept.tests/Feature/SoftDeletedEventNameReuseTest.phpcovering:Testing
vendor/bin/pint --dirty— cleancomposer test(full suite) — 213 passed, 7 pre-existing skipped (unrelated dead test files tracked by Disabling Jetstream's Features::api() silently skips 3 API-token test files on every CI run, forever #154/EmailVerificationTest is an always-skipped test file — a 4th dead file beyond the 3 already tracked in #154 #162), 0 failedFixes #83
🤖 Generated with Claude Code
Generated by Claude Code