You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change introduces a new before metadata property for update and delete change events which contains the state of the changed row before the commit.
It updates the existing implementation to reuse decoding of PostgreSQL's WAL tuples between new and old values.
Integration tests passing.
Proof of Work
metadata.before is now on update and delete (but not insert) messages when REPLICA IDENTITY FULL is set:
postgres_cdc: Add commit_ts_ms to insert, update and delete events — the message after system: must start lowercase and use imperative mood per the enforced commit format (e.g. add, not Add). Should be postgres_cdc: add commit_ts_ms to insert, update and delete events. The other two commits (update integration test..., support "before" data...) are correctly formatted.
Review
Adds commit_ts_ms and before metadata to the postgres_cdc input. The commit-time capture/reset around BEGIN/COMMIT, the before decoding for update (via OldTuple) and delete, and the integration test coverage all look correct and consistent with the existing tuple-decoding patterns. The new message.CommitTime assignment is safely after the existing message == nil guard.
Review
This PR adds a before metadata field to postgres_cdc for update and delete events and refactors the per-operation tuple decoding into a shared decodeTuple helper. The change keeps the flat fleet message shape (additive top-level metadata, raw row body untouched — compliant with CDC standard §5.2.1), correctly resolves unchanged TOAST columns against the old tuple under REPLICA IDENTITY FULL, and is covered by the updated integration test for both update and delete paths. The delete path now errors on unknown column data types (previously a silent no-op), but this only makes it consistent with the insert/update paths and pgoutput never emits other types for these tuples, so it is not a regression.
Review
This PR exposes pre-change row state via a new before metadata key for postgres_cdc update/delete events, and refactors the per-operation tuple-decoding loops into a shared decodeTuple helper.
Reviewed for correctness, CDC §5 conformance, and project Go patterns. Findings:
before is emitted as flat top-level metadata (not a nested before/after/source/op envelope), so it conforms with §5.2.1; the body remains the raw row. The internal/plugins/cdctest gate only checks config field names, which this PR does not touch.
The delete path's default: case changed from lenient (empty) to returning an error, but the stream negotiates proto_version '1' (text mode), so column data types are only n/u/t — the error branch is unreachable, not a regression.
decodeTuple adds an idx >= len(rel.Columns) bounds guard, making it strictly safer than the original loops.
For deletes, Data and BeforeData share the same map, but Data is JSON-marshaled to bytes before becoming the body, so there is no aliasing concern.
New behavior is covered by added integration-test assertions.
josephwoodward
changed the title
postgres_cdc: support "before" data in change events for update and deletes
postgres_cdc: support "before" data in change events for update and delete events
Jun 26, 2026
josephwoodward
changed the title
postgres_cdc: support "before" data in change events for update and delete events
postgres_cdc: support "before" data in change events for UPDATE and DELETE events
Jun 26, 2026
Review
Adds a before metadata field carrying the pre-change row for postgres_cdc update/delete events, and refactors the three inlined pgoutput tuple-decode loops into a shared decodeTuple helper.
Reviewed the refactor against the original insert/update/delete loops (behavior-preserving, with an added bounds guard), the new flat before metadata key (consistent with the existing flat schema metadata — body stays flat, no nested envelope, conforms to the §5.2 fleet shape), and the integration test assertions (insert→update→delete flow correctly checks before.name for both update and delete). No issues found.
Review
Focused change adding a before metadata field to postgres_cdc update/delete events, backed by a refactor that consolidates tuple decoding into a single decodeTuple helper. The before key is emitted as flat top-level metadata (not a nested before/after envelope), conforming to the CDC flat-message standard (§5.2.1). The update branch correctly limits the TOAST fallback to OldTupleType == 'O' (REPLICA IDENTITY FULL), and the new helper adds a defensive bounds check that the original per-branch loops lacked. Integration test coverage asserts the pre-change values for both update and delete. Commit messages conform to the system: message imperative convention.
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
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.
This change introduces a new
beforemetadata property for update and delete change events which contains the state of the changed row before the commit.It updates the existing implementation to reuse decoding of PostgreSQL's WAL tuples between new and old values.
Integration tests passing.
Proof of Work
metadata.before is now on update and delete (but not insert) messages when
REPLICA IDENTITY FULLis set: