Repository navigation
Data history: emit property Delete events on twin/relationship deletion (opt-in) - #130
Merged
Merged
Conversation
…on (opt-in) Data History emitted only the lifecycle Delete row when an entity was deleted, so the property series stopped at the last Update. Anything that rebuilds node/edge values from the latest row per (Id, Key) kept resolving the pre-delete value: a twin re-created with the same id inherited every property the new write did not set. Behind Parameters:EmitPropertyEventsOnDelete (default false, ADT parity) the factory now emits one property Delete row per non-$ top-level property of the deleted twin or relationship, in addition to the lifecycle Delete. Rows are synthesized from the replication row's property image (OldValue), carry the delete's TimeStamp and the removed value, and use the twin/relationship-level $metadata.$lastUpdatedBy for updatedBy (the per-property entry still names the previous writer, #127). A missing image emits nothing and logs a warning rather than a null-valued Delete row. No sink, table or migration change: both sinks already map action/Action. Relationship deletes keep the documented delete-relationships-first contract: each one is its own RelationshipDelete event and gets its own property Delete rows. No DETACH DELETE, no implicit cascade, so a twin delete emits property deletes for the twin's own properties only. Tests: 8 unit cases (flag off unchanged, flag on shape, system keys, relationship variant, updatedBy source, empty image, delete<recreate ordering) and 3 integration cases over live replication (per-property deletes, latest-row-per-key termination after a partial re-create, relationship-then-twin delete ordering). Refs #129 Co-authored-by: Hermes Agent <hermes@nikoraes.local>
nikoraes
force-pushed
the
feat/emit-property-delete-events-129
branch
from
December 2, 2026 13:07
4732721 to
c5acd10
Compare
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #129
Data History emitted only the lifecycle
Deletewhen a twin/relationship was deleted, so the property series stopped at the lastUpdate. Any reconstruction resolving node/edge values from the latest row per(Id, Key)kept answering with the pre-delete value, and a twin re-created with the same id inherited every property the new write did not set.What changes
Opt-in flag
Parameters:EmitPropertyEventsOnDelete(Events service, defaultfalse, envParameters__EmitPropertyEventsOnDelete=true), threadedProgram.cs→SharedEventConsumer→CloudEventFactory.CreateDataHistoryEvents, mirroringTrackLastUpdatedBy's plumbing. With it off the emitted stream is unchanged — the existingCreateDataHistoryEvents_HandlesTwinDeleteEventWithProperties(exactly one event) is untouched and green.CloudEventFactory.CreatePropertyDeleteEventsemits one propertyDeleteper non-$top-level property of the deleted entity, in addition to the lifecycle row (a separate method:CreatePropertyEventsrequires bothOldValueandNewValue):actionDeletekeyremove /proppatch)valueOldValue)id$dtId, or$sourceIdfor a relationshipmodelId$metadata.$model(present for twins, absent on relationships)relationshipId/relationshipTargettimeStampServerClock— neverUtcNowsourceTimeStampupdatedByTrackLastUpdatedBy: the twin/relationship-level$metadata.$lastUpdatedBy, not the per-property entry (#127)subject<id>or<id>/relationships/<relationshipId>$-keys never produce an event. A twin that carries no properties produces none. A missing/empty replication image produces none and logs a warning — never a null-valuedDeleterow, which would be indistinguishable from a real value change.No sink, table or migration change:
KustoEventSink.BuildPropertyEventMappingsandPostgresEventSinkalready mapaction/Action.Relationships keep the documented operating contract. Deleting a twin does not cascade here: AGE rejects a plain
DELETEof a vertex that still has edges, so the caller deletes the relationships first, and eachDeleteRelationshipAsyncis its own event with its own propertyDeleterows.DETACH DELETEis deliberately not introduced in this PR (the issue is explicit about that) — the diff touches no client code.Two findings worth your eye
TimeStamp. The issue's §3 says the events within a transaction share oneServerClock. Measured on the relationship delete (13:04:32.078716Zvs its lifecycle row): they are clustered but not equal — the per-rowServerClockof a pgoutput message is not the transaction's commit stamp. The invariant the reconstruction relies on is ordering (Delete < Createacross transactions), which holds; the integration test asserts a transaction window rather than equality, with the measurement in a comment.Actioncolumn is a pre-existing gap, not one this PR introduces.BuildPropertyEventMappingshas always mappedAction←$.action, while the schema table indocs/how-to-guides/data-history-kusto.mdxomitted it. I added the row plus the.alter-merge table AdtPropertyEvents add Action:stringstep for hand-created tables. I could not exercise ADX queued ingestion here, so I did not claim what it does with a mapped-but-missing column — the doc states the column is required and how to add it.Tests
Unit (
CloudEventFactoryTests, 8 new): flag off → exactly 1 lifecycle event; flag on → lifecycle + one per property with correctkey/value/id/modelId/subject/timeStamp, nosourceTimeStamp;$-keys never emit; relationship variant;updatedByfrom twin-level metadata while the per-property entry names the previous writer; twin without properties → no extras;null/empty image → nothing and no throw; delete→re-create ordering.Integration (
EventsIntegrationTests, 3 new, over live replication; the shared fixture runs the consumer with the flag on — flag-off byte-identical behaviour is pinned by the unit tests):Delete+ 2 propertyDeleterows sharing the delete timestamp, with model id and values;a+b→ delete → re-create withaonly → latest row per(Id, Key)isDeleteforband the re-create'sCreatefora, and thatCreateis strictly newer;Delete+ one propertyDeleteper edge property, then the twin's lifecycleDelete+ one per twin property, in that TimeStamp order, nothing emitted twice.Verified on
ghcr.io/konnektr-io/age-pgvector:16-1.6.0-standard-trixie(PG 16.15, AGE 1.6.0, cnpg driver):AgeDigitalTwins.Events.Test117 passed / 0 failed,AgeDigitalTwins.Test358 passed / 8 skipped / 0 failed. The PG18/AGE 1.8 and apache/AGE legs are CI's to cover.Docs
data-history-kusto.mdx(opt-in section,Actionin the schema, note on the reconstruction query),data-history-postgres.mdx(global key, delete-row semantics, note),configuration.mdx(Events service key),CLAUDE.md(event semantics, delete-relationships-first contract).