owenrusk.dev

casebench

test cases straight onto the board.

git clone https://owenrusk.dev/casebench.git

commit c263b32922570596542a29c027b4be03dde977af
parent 0b5e93985d5a7abac3743d8c435821af2a8051eb
author Owen Rusk <owen@papermothgames.com>
date   2025-03-18 15:31:09 -0500
put: putting a case again replaces it
casebench/db.py+4-1
diff --git a/casebench/db.py b/casebench/db.py
index b75e378..c995a2e 100644
--- a/casebench/db.py
+++ b/casebench/db.py
@@ -13,11 +13,14 @@ def player_id(conn: psycopg.Connection, handle: str) -> str | None:
 
 
 def put(conn: psycopg.Connection, player: str, case: Case) -> None:
+    # putting a case again replaces it. tess changes cases faster than i can pull them.
     with conn.transaction():
         conn.execute(
-            "insert into board_cases (player_id, case_id, title, source) values (%s, %s, %s, 'bench')",
+            "insert into board_cases (player_id, case_id, title, source) values (%s, %s, %s, 'bench')"
+            " on conflict (player_id, case_id) do update set title = excluded.title",
             (player, case.id, case.title),
         )
+        conn.execute("delete from board_items where player_id = %s and case_id = %s", (player, case.id))
         for position, item in enumerate(case.items):
             conn.execute(
                 "insert into board_items (player_id, case_id, item_id, position, title, body)"