| 36362 |
amit |
1 |
-- Migration: add unique constraint on fofo.fofo_order (fofo_id, invoice_number)
|
|
|
2 |
-- Paired with idempotent createAndGetFofoOrder() code: concurrent duplicate
|
|
|
3 |
-- inserts (client double-clicks, upstream retries) used to deadlock on the
|
|
|
4 |
-- idx_invoice_number gap lock — with the unique key, the loser gets a clean
|
|
|
5 |
-- DataIntegrityViolationException which the code catches and re-selects.
|
|
|
6 |
-- Pre-check on 2026-04-22: zero existing duplicate (fofo_id, invoice_number)
|
|
|
7 |
-- groups in the table, so the constraint adds cleanly.
|
|
|
8 |
-- Online DDL on InnoDB 5.7+; brief metadata lock only at commit.
|
|
|
9 |
|
|
|
10 |
ALTER TABLE fofo.fofo_order
|
|
|
11 |
ADD UNIQUE KEY uk_fofo_order_fofo_invoice (fofo_id, invoice_number);
|
|
|
12 |
|
|
|
13 |
-- Rollback:
|
|
|
14 |
-- ALTER TABLE fofo.fofo_order DROP INDEX uk_fofo_order_fofo_invoice;
|