Ignore:
Timestamp:
09/16/26 23:37:15 (13 days ago)
Author:
Stefan <trsunovstefan@…>
Branches:
main
Children:
8b447ef
Parents:
df05838
Message:

add reserved_quantity and modify the phases, add v_03.png and v_03.xml for P1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/P2-RelationalDesign/RelationalDesignAIUsage.md

    rdf05838 r9577c79  
    6969> against the faculty database. No AI involvement is possible there — it needs a
    7070> live connection to your assigned database.
     71
     72### Session 3 — 2026-09-16
     73
     74Driven by the same design review logged in full in
     75[ERModelAIUsage](../P1-ConceptualModel/ERModelAIUsage.md#session-3--2026-09-16):
     76a sell order had nothing to check `holdings.quantity` against except itself,
     77so nothing stopped two sell orders from being granted the same units.
     78
     79Changes to the P2 artefacts:
     80
     81- `holdings` gained `reserved_quantity numeric(20,4) NOT NULL DEFAULT 0
     82  CHECK (reserved_quantity >= 0 AND reserved_quantity <= quantity)` in
     83  `schema_creation.sql`.
     84- `v_portfolio` gained `reserved_quantity` and the derived
     85  `available_quantity = quantity - reserved_quantity`.
     86- [RelationalDesign](RelationalDesign.md) gained a "Reservation and the order
     87  lifecycle" section explaining why the check is enforced at the database
     88  level rather than trusted to application code, and why it does not conflict
     89  with the existing `SELECT … FOR UPDATE` locking on the sell path.
     90- `data_load.sql` needed no change — `reserved_quantity` defaults to 0, which
     91  is correct for every seeded holding.
     92
     93Re-run end to end against the live database on `localhost:5433`
     94(`-init` then `-load-data`), and against a manually seeded 2 BTC holding to
     95reproduce the exact scenario that motivated the change — see
     96[UseCase0005Implementation](../P4-Prototype/UseCase0005Implementation.md) for
     97the transcript.
     98
     99**What I decided:** to add the `CHECK` constraint rather than rely on
     100`trade.go` alone to keep the reservation consistent — the same reasoning
     101already applied to `avg_price NOT NULL` in session 2.
Note: See TracChangeset for help on using the changeset viewer.