-- Adds an optional idempotency key to sales (product_orders) so a duplicate
-- "Create Sale" submission (double-click / network retry) resolves to the SAME
-- sale instead of creating a second one.
--
-- Safe for existing data: the column is NULLable with no default, so every
-- existing row stays NULL. MySQL allows multiple NULLs under a UNIQUE index,
-- so the unique constraint does not conflict with historical rows.
ALTER TABLE product_orders ADD COLUMN idempotency_key VARCHAR(64) NULL DEFAULT NULL;
ALTER TABLE product_orders ADD UNIQUE INDEX uq_product_orders_idempotency_key (idempotency_key);
