feat: record and list translation change history [T-2408]
Update (closure, 93d71ea2): a failed history write now fails the whole edit on every database (one transaction per edit; a single queue on SQLite), imports record history too, and the project-locale / user indexes exist on every database. Where the text below says a failed history write is only logged, that no longer applies.
I added translation history, but none of it has been compiled or run: I had no shell here, so no tsc, no jest and no migration against a real database.
Gap: the editor can't show who changed a translation or what it said before. Each save overwrites the value with no record. Reviewing a translator's work and undoing a bad edit both depend on that record. The code has no history, comments or review state at all (today's rotation picked Collaboration).
What changed (api/src):
- Record on edit: saving a translation now writes a history row with the previous value, the new value and the user. A save that changes nothing writes no row, and a change made with an API client records no user.
- New table:
translation_history, withentity/translation-history.entity.tsand migration1794096000000-add-translation-history.tsfor Postgres, MySQL and SQLite. Rows are deleted with their term or locale, and the user link is cleared if the user is deleted. - New endpoint:
GET /api/v1/projects/:projectId/translations/:localeCode/history?termId=…&limit=…returns entries newest first. It needs the same permission as viewing translations, so viewers can read it. The limit is bounded 1–100 (default 50),termIdis required, and an unknown locale returns 404. It returns the user's id and name, not their email. - Wiring: the response type is in
domain/http.tsand the entity is registered inapp.module.ts. - Failure handling: if the history write fails, the failure is logged and the translation save still succeeds.
- Tests:
translation.controller.spec.tscovers the limit bounds, recording, the no-change case, the API-client case, the failed-write case and the endpoint's output and errors.
What I could not run: the three hand-written migrations are the main risk. I copied the existing migrations' naming and types, including MySQL's utf8mb4_bin collation so the foreign keys match, but a reviewer should run the migration on each database. I also did not regenerate docs-website/static/docs/api/v1/swagger.json. The repository has no AGENTS.md or CHANGELOG to follow.
Next slices:
- Record history for bulk imports too.
- Add a history panel to the editor UI.
- Add a "restore this version" action.
- Add per-translation comments.
Task T-2408 · opened by an agent run; the description above is the run's own summary. Review before merging — merge policy is governed by the Work's merge-policy settings.
Summary by cubic
Records translation change history so the editor can show who changed a translation and what it said before. Each save and each import writes a history row with the previous value, the new value, a per-translation change number, and the user; no-op saves write nothing and API-client changes record no user.
New Features
- Saves and imports each run in one transaction; overlapping edits and imports are ordered so every entry records the value it actually replaced, and a failed history write fails the whole edit.
- Transactions lock rows in a fixed order (project-counter writes take the project first, edits lock locale, then term, then translation), SQLite transactions are serialized, and deadlocks or lock timeouts answer 503 with
Retry-After: 1, so edits and imports stay one unbroken chain on every database. GET /api/v1/projects/:projectId/translations/:localeCode/historylists entries newest first by change number; requirestermId, clampslimitto 1–100 (default 50), returns 404 for unknown locales, and exposes user id and name but not email.- New
translation_historytable with migration for Postgres, MySQL, and SQLite; rows cascade-delete with their term or locale,SET NULLon user deletion, and have indexes on locale and user.
Migration
- Migrations were verified on SQLite, Postgres 15, and MySQL 5.7/8.4;
swagger.jsonwas not regenerated.