refactor: extract shared transaction helper from duplicated runReservationTransaction/runEpicTransaction

Aperta
#121 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Read the transaction helpers in internal/comms/reservation.go and internal/org/epic.go, then inspect internal/db and search the codebase for other copies of the pattern. Extract the shared helper there and add its unit tests. Done means both callers use it, the existing tests for both packages pass, and no third copy remains.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

PR #120 introduced two structurally identical transaction helpers as part of the lint-debt resolution:

  • internal/comms/reservation.go → runReservationTransaction(work, commit, rollback func() error) error
  • internal/org/epic.go → runEpicTransaction(work, commit, rollback func() error) error

Both are byte-for-byte identical in logic: committed flag, deferred rollback guarded with sql.ErrTxDone, and errors.Join for error aggregation. The duplication was intentional — the spec (design.md) scoped work as per-package correctness without cross-cutting refactors.

Proposed Change

Extract a shared helper into internal/db, e.g.:

// RunTransaction executes work within a transaction lifecycle.
// It calls commit on success and ensures rollback is called exactly
// once on failure, guarding against sql.ErrTxDone.
func RunTransaction(work, commit, rollback func() error) error

Then replace both package-local copies with calls to db.RunTransaction.

Acceptance Criteria

  • Shared helper exists in internal/db
  • internal/comms/reservation.go uses the shared helper
  • internal/org/epic.go uses the shared helper
  • Existing tests for both packages continue to pass
  • Shared helper has its own unit tests in internal/db
  • No third copy of this pattern exists in the codebase

Context

  • Introduced in: #120
  • Convention: go.md CS-010 [SHOULD] — avoid duplicated logic across packages
  • Priority: Low — both copies are correct and tested; this is a maintainability improvement to prevent a third copy from appearing
Lingua principale
Go
Stelle
0
Fork
9
Merge medio
1g 14h
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di unbound-force/replicator

Tutte le issue di unbound-force/replicator

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.