Skip to content

WRD history does not record deletes or cascaded effects, and changesets have no commit order #10

Description

@RichardHoekstra

With keephistorydays set on a type, updates and closes are recorded in wrd.changes, but two things are missing:

  1. 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").

  2. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions