refactor(backend): migrate db.DB to db.Conn PoolProxy across all handlers

Replace direct *pgxpool.Pool usage with PoolProxy wrapper across the entire backend:

- db.DB renamed to db.Conn (*pgxpool.Pool -> *PoolProxy)
- JWT functions now accept context.Context instead of using context.Background()
- Handler DB calls route through PoolProxy for per-test transaction support
- Fixture/helper/testdb functions accept Querier interface for decoupling
- Query ordering fixed in bookings handlers: COUNT after data query to avoid pgx conn busy
- Time truncation fixed: time.Date instead of Truncate(24*time.Hour) for week start calc
- testmain_test.go files updated with SeedBaseline and NewPoolProxy

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-21 19:28:54 +01:00
co-authored by Sisyphus
parent c69a243f75
commit 3d0e2afc4c
39 changed files with 751 additions and 638 deletions
+4 -4
View File
@@ -47,7 +47,7 @@ func GetPatchTests(w http.ResponseWriter, r *http.Request) {
ORDER BY name
`
rows, err := db.DB.Query(r.Context(), query)
rows, err := db.Conn.Query(r.Context(), query)
if err != nil {
http.Error(w, "Failed to fetch patch tests: "+err.Error(), http.StatusInternalServerError)
return
@@ -93,7 +93,7 @@ func CreatePatchTest(w http.ResponseWriter, r *http.Request) {
`
var id string
err := db.DB.QueryRow(r.Context(), query, req.Name, req.Description, req.NoticeDurationHours, req.ExpiryMonths, req.ServiceIDs).Scan(&id)
err := db.Conn.QueryRow(r.Context(), query, req.Name, req.Description, req.NoticeDurationHours, req.ExpiryMonths, req.ServiceIDs).Scan(&id)
if err != nil {
http.Error(w, "Failed to create patch test: "+err.Error(), http.StatusInternalServerError)
return
@@ -156,7 +156,7 @@ func UpdatePatchTest(w http.ResponseWriter, r *http.Request) {
query += " WHERE id = $" + strconv.Itoa(i)
args = append(args, id)
_, err := db.DB.Exec(r.Context(), query, args...)
_, err := db.Conn.Exec(r.Context(), query, args...)
if err != nil {
http.Error(w, "Failed to update patch test", http.StatusInternalServerError)
return
@@ -173,7 +173,7 @@ func DeletePatchTest(w http.ResponseWriter, r *http.Request) {
return
}
_, err := db.DB.Exec(r.Context(), "DELETE FROM patch_tests WHERE id = $1", id)
_, err := db.Conn.Exec(r.Context(), "DELETE FROM patch_tests WHERE id = $1", id)
if err != nil {
http.Error(w, "Failed to delete patch test: "+err.Error(), http.StatusInternalServerError)
return