Skip to content

fix(maintenance): cambios con su historial en una transacción y altas simultáneas - #12

Merged
bpstack merged 2 commits into
claude/compassionate-planck-gh6aoffrom
opencode/fix-maintenance-history
Oct 12, 2026
Merged

bpstack merged 2 commits into
claude/compassionate-planck-gh6aoffrom
opencode/fix-maintenance-history

Conversation

@bpstack

@bpstack bpstack commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Cambios

  • Cada cambio de un parte y su fila de historial se escriben en una transacción.
  • Dos altas a la vez ya no chocan en el id del día, y subir fotos en paralelo respeta el límite de 5 (las que sobran se borran de Cloudinary).

Por qué

Un fallo a mitad dejaba el cambio sin historial, y altas o fotos simultáneas daban 500 o pasaban del límite.

- maintenance-repository.ts: create, update, updateStatus, updatePriority,
  addResolutionNotes, delete and restore run their write and history rows
  inside withTransaction; every query goes through dbx().
- atomic-history.test.ts: each of the seven rolls back when the history
  insert fails, and writes both rows on one connection when it succeeds.

Why: the two writes were separate queries, so a failed history insert left
the change saved without a trace and answered 500, inviting a retry that
applied it twice. Checked against the local database: the seven operations
answer 200 and leave their eight history rows.
- Retry a new report with the next number of the day when another one took
  its id (up to 5 attempts, each in its own transaction).
- Count a report's photos again under a lock on the report when saving one;
  an upload that loses the race is removed from Cloudinary and answers 400.
- Document both rules, the 999 reports a day left as is, and that changes
  and their history now share a transaction.

Two reports created at once read the same last id and the second one died
with a 500 on the duplicate key. Photos were counted before the upload to
Cloudinary, so uploads in parallel went past the limit of 5.
@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
four-points Ready Ready Preview Oct 12, 2026 8:02am UTC

@bpstack
bpstack merged commit baedd94 into claude/compassionate-planck-gh6aof Oct 12, 2026
6 checks passed
@bpstack
bpstack deleted the opencode/fix-maintenance-history branch October 12, 2026 19:02

This branch was successfully deployed

1 active deployment
Preview — c237ce32 Deployed Oct 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant