Skip to content

Fix duplicate bookings: DB constraint + frontend result handling#1

Open
RadekHavelka wants to merge 3 commits into
masterfrom
fix/duplicate-bookings
Open

Fix duplicate bookings: DB constraint + frontend result handling#1
RadekHavelka wants to merge 3 commits into
masterfrom
fix/duplicate-bookings

Conversation

@RadekHavelka

Copy link
Copy Markdown
Owner

Problem

Customers were occasionally receiving two booking confirmations for the
same time slot. The root cause was twofold:

  1. Frontend (BookingForm.tsx) fires two identical GraphQL mutations
    concurrently via Promise.all on every form submission, simulating a
    double-click race condition.

  2. Backend had no uniqueness protection — two concurrent INSERTs for
    the same stylist + time slot both succeeded. SQLite's write locking
    caused the duplicate to be non-deterministic (it didn't happen every
    time), masking the real issue.

Changes

Backend

  • New migration (Version20260625000000.php): adds a UNIQUE INDEX on
    (stylist_id, start_time) in barbershop_bookings. The DB atomically
    rejects the second concurrent INSERT regardless of application-level timing.
  • Doctrine mapping (Booking.dcm.xml): mirrors the constraint so schema
    validation tools stay consistent.
  • DoctrineBookingRepository::save(): catches
    UniqueConstraintViolationException and rethrows as DomainException,
    so the GraphQL mutation returns a clean errors[] response instead of
    a 500.

Frontend

  • BookingForm.tsx: the duplicate Promise.all call is intentionally
    kept as a test harness. Fixed the result handling — previously only
    result[0] was checked (non-deterministically the failed one ~50% of
    the time). Now all results are checked: success is reported if any call
    succeeded, error is shown only if all calls failed.

Project

  • .gitignore: added to exclude vendor/, node_modules/, .next/,
    runtime dirs, .env.local files, and IDE folders.
  • .claude/commands/audit-duplicate-writes.md: Claude Code skill that
    audits write paths for missing DB constraints, unguarded repository save
    methods, and frontend double-submit patterns.

Radek Havelka and others added 3 commits June 25, 2026 15:59
- Add UNIQUE INDEX on (stylist_id, start_time) via migration so the DB
  atomically rejects the second concurrent INSERT even under a race condition
- Mirror the constraint in the Doctrine XML mapping for schema validation
- Catch UniqueConstraintViolationException in DoctrineBookingRepository::save()
  and rethrow as DomainException so the GraphQL mutation returns a clean
  errors[] response instead of a 500
- Add .gitignore covering vendor/, node_modules/, .next/, temp/*, var/*,
  logs/*, .env.local files, .idea/, and .claude/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The skill audits write paths for three layers of duplicate-write
vulnerability: missing DB unique constraints, unguarded repository
save methods, and frontend double-submit patterns. It reports findings
and offers to apply fixes for each layer.

Tighten .gitignore to exclude only .claude/settings.local.json instead
of the whole .claude/ directory, so project-level skills are committed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both concurrent calls still fire (intentional test harness), but now
all results are checked — success is reported if any call succeeded.
Previously only result[0] was checked, which failed ~50% of the time
due to non-deterministic server-side processing order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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