With keephistorydays set on a type, updates and closes are recorded in wrd.changes, but two things are missing:
-
Deleting an entity (WRDType.delete / DeleteEntities) leaves no trace. The entity simply disappears from wrd.entities, and later reads of other entities' history can no longer reconstruct references to it (test_wrd_history.ts already documents this as "can't reconstruct after a delete").
-
The effects PostgreSQL cascades from a delete are not recorded either: attachments and links to the deleted entity are deleted (leftentity/rightentity ON DELETE CASCADE) and settings of other entities referring to it are dropped (entity_settings.setting ON DELETE CASCADE). A type that keeps history therefore silently loses data without a history row.
Separately, wrd.changesets has no commit-ordered position. changesets.id is a sequence value allocated when the changeset is created and creationdate is the time of the first change, so neither tells a reader "everything up to here has been committed": a lower id can still appear after a higher one. That makes it impossible for exports, synchronisations or dashboards to reliably resume from a known point.
Proposal (patch with tests ready)
- Record a
delete change before an entity is deleted, carrying the full old entity, and record a change for every cascaded effect on a type that keeps history. A new wrd.changes.cause column refers to the recorded deletion that caused the effect. GetChanges() reports changetype delete and the cause.
- Number changesets in commit order:
wrd.schemas.historyhead advances by one per changeset just before commit (the row lock is held only during the commit) and the number is stored in wrd.changesets.historyseqnr. A rollback leaves nothing behind. WRDSchemaType.getHistoryHead() and ListChangesets().historyseqnr expose it.
- No new cost when no type in a schema keeps history.
A second, smaller patch fills two fields that already exist but that the JS API leaves empty: wrd.changesets.entity/userdata (the acting user, as the HareScript API already records) and wrd.changes.source, with a setChangeSource() / SetWRDChangeSource() to describe what caused the changes in a work (an import, a task, a request). GetChanges() then returns source as its documentation already says it does.
Happy to split or rename things; I mainly want to check this is in scope before opening the PR.
Patch on a branch, not yet a PR: master...RichardHoekstra:platform:wrd-history-observability
With
keephistorydaysset on a type, updates and closes are recorded inwrd.changes, but two things are missing:Deleting an entity (
WRDType.delete/DeleteEntities) leaves no trace. The entity simply disappears fromwrd.entities, and later reads of other entities' history can no longer reconstruct references to it (test_wrd_history.tsalready documents this as "can't reconstruct after a delete").The effects PostgreSQL cascades from a delete are not recorded either: attachments and links to the deleted entity are deleted (
leftentity/rightentityON DELETE CASCADE) and settings of other entities referring to it are dropped (entity_settings.settingON DELETE CASCADE). A type that keeps history therefore silently loses data without a history row.Separately,
wrd.changesetshas no commit-ordered position.changesets.idis a sequence value allocated when the changeset is created andcreationdateis the time of the first change, so neither tells a reader "everything up to here has been committed": a lower id can still appear after a higher one. That makes it impossible for exports, synchronisations or dashboards to reliably resume from a known point.Proposal (patch with tests ready)
deletechange before an entity is deleted, carrying the full old entity, and record a change for every cascaded effect on a type that keeps history. A newwrd.changes.causecolumn refers to the recorded deletion that caused the effect.GetChanges()reports changetypedeleteand the cause.wrd.schemas.historyheadadvances by one per changeset just before commit (the row lock is held only during the commit) and the number is stored inwrd.changesets.historyseqnr. A rollback leaves nothing behind.WRDSchemaType.getHistoryHead()andListChangesets().historyseqnrexpose it.A second, smaller patch fills two fields that already exist but that the JS API leaves empty:
wrd.changesets.entity/userdata(the acting user, as the HareScript API already records) andwrd.changes.source, with asetChangeSource()/SetWRDChangeSource()to describe what caused the changes in a work (an import, a task, a request).GetChanges()then returnssourceas its documentation already says it does.Happy to split or rename things; I mainly want to check this is in scope before opening the PR.
Patch on a branch, not yet a PR: master...RichardHoekstra:platform:wrd-history-observability