Each item (stock) in the inventory is modelled as a row.
stock
=====
code: primary key
itemType: foreign key to items table
available: boolean
So to reduce stock what is done is something like:
UPDATE stock SET available = false where code = 'something' and available = true
This is done in a transaction. So it looks like:
BEGIN TRANSACTION;
UPDATE stock SET available = false where code = 'something1' and available = true;
UPDATE stock SET available = false where code = 'something2' and available = true;
UPDATE stock SET available = false where code = 'something3' and available = true;
COMMIT;
I suspect a race condition is possible. If I have 2 queries like the above running at approximately the same time, would they both succeed?