Changes between Initial Version and Version 1 of RelationalAIUsage


Ignore:
Timestamp:
09/24/26 13:41:33 (2 days ago)
Author:
231285
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RelationalAIUsage

    v1 v1  
     1= Relational Design AI Usage =
     2
     3== Name of AI service/solution that was used ==
     4
     5'''Claude Code''' (Anthropic)
     6
     7 * '''URL:''' `https://claude.com/claude-code`
     8 * '''Type of service/subscription:''' Claude subscription, model Claude Opus 4.7 (1M context).
     9
     10== Final result ==
     11
     12=== Diagram ===
     13
     14The student produces `relational_schema.jpg` in DBeaver from the live `project` schema; see !RelationalDesign for instructions.
     15
     16=== Results in details / description ===
     17
     18The AI:
     19
     20 * Consolidated two inconsistent draft schemas (`server/db/db.sql` and `server/db/schema.sql`) into a single `schema_creation.sql`.
     21 * Corrected foreign-key errors in the original (the `crypto_id` column in `holdings`, `orders`, and `transactions` had been pointed at both `users(id)` and `crypto(id)`; the AI split it into separate `user_id` and `crypto_id` columns per `ep-diagram.md`).
     22 * Added two convenience views, `v_latest_prices` and `v_portfolio`, to keep the Go CLI simple.
     23 * Produced a sample-data script `data_load.sql` that TRUNCATEs and re-inserts deterministic rows, so the "must work on empty DB and on a DB that already has data" requirement from P2 is met.
     24 * Documented normalisation up to 3NF and the intentional denormalisation of `holdings.avg_price`.
     25
     26== Summary of AI involvement ==
     27
     28||= =||= Session 1 — 2026-04-21 =||= Session 2 — 2026-08-06/07 =||
     29|| '''What I brought''' || My own draft SQL (`db.sql`, `schema.sql`) and the model in `ep-diagram.md` || The schema as it stood after session 1 ||
     30|| '''What the AI did''' || Reviewed my SQL, found the foreign-key errors, consolidated two inconsistent drafts into one script || Reviewed the schema again; one constraint change, plus documentation of the transformation ||
     31|| '''What I decided''' || Which corrections to adopt, to keep both balance columns, to drop the secret-question fields || To make `avg_price` `NOT NULL` rather than handle nulls in application code ||
     32
     33The relational model in this phase is a transformation of ''my'' ER model, and the
     34foreign-key errors the AI found in session 1 were errors in ''my'' draft SQL — that
     35review is the single most useful thing the AI did on this phase.
     36
     37== Entire AI usage log ==
     38
     39See ERModelAIUsage — the full transcript of the 2026-04-21 conversation covers both P1 and P2 work. The specific prompts that drove the relational-design output were the same "make it work and make it fill in or to follow all of the needed instructions" instruction and the student's subsequent "do everything that you need to do".
     40
     41> '''Student action required:''' append any future consultations where you asked the AI to refine the schema, tune constraints, or write additional queries.
     42
     43
     44=== Session 2 — 2026-08-06 / 2026-08-07 ===
     45
     46Prompts are logged in full in ERModelAIUsage (section "Session 2 — 2026-08-06 / 2026-08-07");
     47the one that drove this phase was ''"Also fix some database things or golang things if you think we can do it better"''. Changes to the P2 artefacts:
     48
     49 * `holdings.avg_price` changed from nullable to `NOT NULL DEFAULT 0 CHECK (avg_price >= 0)`. Reason: it feeds the P/L arithmetic in `v_portfolio`, and
     50   SQL arithmetic involving `NULL` produces `NULL`, so a nullable average would
     51   have silently blanked the unrealised-P/L column of a real position. A related
     52   crash path in the Go code (scanning a `NULL` average into a non-nullable
     53   `float64`, which was reported to the user as "Insufficient holding") was fixed
     54   at the same time.
     55 * !RelationalDesign gained an explicit account of the
     56   partial transformation: which ER construct each foreign key comes from, that
     57   M:N relationships with attributes become tables whose foreign-key pair is a
     58   `UNIQUE` constraint, and that total participation becomes `NOT NULL` — which is
     59   why `transactions.related_order` is the one nullable foreign key.
     60 * The candidate keys of `holdings` and `watchlist_items` are now documented as
     61   the relationship keys `{user_id, crypto_id}` and `{watchlist_id, crypto_id}`.
     62
     63Both scripts were re-run end to end against PostgreSQL 16 after these changes.
     64
     65> '''Still outstanding:''' `relational_schema.jpg` must be exported from DBeaver
     66> against the faculty database. No AI involvement is possible there — it needs a
     67> live connection to your assigned database.
     68
     69=== Session 3 — 2026-09-16 ===
     70
     71Driven by the same design review logged in full in
     72ERModelAIUsage (section "Session 3 — 2026-09-16"):
     73a sell order had nothing to check `holdings.quantity` against except itself,
     74so nothing stopped two sell orders from being granted the same units.
     75
     76Changes to the P2 artefacts:
     77
     78 * `holdings` gained `reserved_quantity numeric(20,4) NOT NULL DEFAULT 0 CHECK (reserved_quantity >= 0 AND reserved_quantity <= quantity)` in
     79   `schema_creation.sql`.
     80 * `v_portfolio` gained `reserved_quantity` and the derived
     81   `available_quantity = quantity - reserved_quantity`.
     82 * !RelationalDesign gained a "Reservation and the order
     83   lifecycle" section explaining why the check is enforced at the database
     84   level rather than trusted to application code, and why it does not conflict
     85   with the existing `SELECT … FOR UPDATE` locking on the sell path.
     86 * `data_load.sql` needed no change — `reserved_quantity` defaults to 0, which
     87   is correct for every seeded holding.
     88
     89Re-run end to end against the live database on `localhost:5433`
     90(`-init` then `-load-data`), and against a manually seeded 2 BTC holding to
     91reproduce the exact scenario that motivated the change — see
     92UseCase0005Implementation for
     93the transcript.
     94
     95'''What I decided:''' to add the `CHECK` constraint rather than rely on
     96`trade.go` alone to keep the reservation consistent — the same reasoning
     97already applied to `avg_price NOT NULL` in session 2.