The first template of the source-aligned family: one data product per source system, capturing a database by CDC and turning what it emits into what a canonical product accepts. It runs on the Integration Bus, not in a domain, and is deployed with the `data-bus` CLI. What it produces, and what its tests hold it to: raw topics in the source's own shape; deterministic identity, so a re-snapshot upserts rather than duplicating; validation against the canonical product's rules before publishing, with what fails going to the product's own dead-letter topic with the reason; keying by the canonical identifier; provenance in headers; and an archive in the bus object store that can be replayed back onto the raw topic. The worked example captures an ERP customer table and delivers into Canonical Party in the digital-core domain: 12 smoke checks, 37 unit tests, including a poison record that is quarantined while the next record still arrives. The canonical template's topics now declare the key producers must set, which is the other half of that contract. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
86 lines
3.5 KiB
YAML
86 lines
3.5 KiB
YAML
# What the source fixture holds, and what {{product_name}} must make of it.
|
|
#
|
|
# The test modules beside this file are generic: they are the same in every source-aligned CDC
|
|
# product, and everything specific to this one is here. Rows come from
|
|
# fixture/init/010_customer.sql; the canonical identifiers are not written down, because the
|
|
# tests derive them with the platform's identity rule, which is what the transform implements.
|
|
|
|
source:
|
|
system: "{{system}}"
|
|
object: "{{source_schema}}.{{source_object}}"
|
|
table: "{{source_schema}}.{{source_object}}"
|
|
key: "id"
|
|
rows: 6
|
|
# The columns a test replays a source row with. Only what the transform reads: a replayed
|
|
# record is JSON on the raw topic, and a column the raw contract types differently (a DATE
|
|
# the connector encodes as a number) would be refused by the transform's parser.
|
|
replay_columns: ["id", "cust_name", "cust_type", "status_code", "trading_name"]
|
|
|
|
capture:
|
|
raw_topic: "raw.{{system}}.{{source_schema}}.{{source_object}}"
|
|
# What the capture adds around a source row. A record a test puts on the raw topic carries it
|
|
# too, so a replayed record is indistinguishable from a captured one.
|
|
replay_envelope: {"__op": "r", "__lsn": 0, "__source_ts_ms": 0}
|
|
# Fields the capture adds to every record, so a consumer can tell what happened and when.
|
|
provenance_fields: ["__op", "__lsn", "__source_ts_ms"]
|
|
# A row inserted by a test, to prove capture is live rather than a one-off snapshot. It is
|
|
# removed again afterwards; ids above 900 are the tests' own.
|
|
probe:
|
|
insert: "INSERT INTO {{source_schema}}.{{source_object}} (id, cust_name, cust_type, status_code) VALUES (900, 'Live Capture Ltd', 'O', 'A')"
|
|
delete: "DELETE FROM {{source_schema}}.{{source_object}} WHERE id = 900"
|
|
source_key: 900
|
|
|
|
transform:
|
|
target_topic: "{{target_domain}}.{{target_product}}.{{target_table}}.inbound"
|
|
target_key: "party_id"
|
|
headers: ["source_system", "source_object", "source_key", "produced_by"]
|
|
accepted:
|
|
- source_key: 1
|
|
record:
|
|
party_type: "Person"
|
|
legal_name: "Ada Lovelace"
|
|
also_known_as: null
|
|
party_status: "Active"
|
|
- source_key: 2
|
|
record:
|
|
party_type: "Person"
|
|
legal_name: "Grace Hopper"
|
|
also_known_as: null
|
|
party_status: "Prospect"
|
|
- source_key: 3
|
|
record:
|
|
party_type: "Company"
|
|
legal_name: "Semprini Holdings Ltd"
|
|
also_known_as: "Semprini"
|
|
party_status: "Active"
|
|
- source_key: 4
|
|
record:
|
|
party_type: "Company"
|
|
legal_name: "Northwind Trading Co"
|
|
also_known_as: "Northwind"
|
|
party_status: "Closed"
|
|
rejected:
|
|
- source_key: 5
|
|
reason_contains: "party_status"
|
|
- source_key: 6
|
|
reason_contains: "party_type"
|
|
# Records put straight onto the raw topic, as the connector would have written them: one the
|
|
# transform must refuse, one it must accept. Together they prove a bad record is quarantined
|
|
# rather than stopping the flow.
|
|
probe_records:
|
|
bad:
|
|
record: {"id": 901, "cust_name": "Poison Ltd", "cust_type": "Q", "status_code": "A", "__op": "c", "__lsn": 0, "__source_ts_ms": 0}
|
|
source_key: 901
|
|
reason_contains: "party_type"
|
|
good:
|
|
record: {"id": 902, "cust_name": "Survivor Ltd", "cust_type": "O", "status_code": "A", "__op": "c", "__lsn": 0, "__source_ts_ms": 0}
|
|
source_key: 902
|
|
party_type: "Company"
|
|
legal_name: "Survivor Ltd"
|
|
|
|
delivery:
|
|
# Where the canonical product puts what this product sends it.
|
|
schema: "canonical_party"
|
|
table: "party"
|
|
key: "party_id"
|