first working template

This commit is contained in:
paul committed 2026-09-18 08:56:37 +12:00
1 parent 62a3714562
commit ca6bea351a
21 files changed
+684 -31

No files matched your search

+77 -1
View File
@@ -64,7 +64,7 @@ products/<slug>/
010_schema.sql schema, pg_graphql directive, shared trigger function
020_tables.sql one CREATE TABLE per entity, foreign keys, association tables
030_api.sql grants for the API role and the product's GraphQL RPC endpoint
040_seed.sql optional sample rows
040_seed.sql sample rows with fixed uuids; the unit tests are written against them
graphql/
schema.graphql documents the reflected GraphQL surface (not loaded anywhere)
smoke.graphql query run by `test`; must return no errors
@@ -76,6 +76,13 @@ products/<slug>/
010_replication.sql registers each ODS table with pg_duckpipe
trino/
smoke.sql one count per table through Trino
tests/
expectations.yaml what the seed holds and how it must behave: the only generated test file
test_seed.py generic tests, copied unchanged from this template:
test_constraints.py seed rows and values; constraints refuse bad updates; updated_at
test_graphql.py every column reflected; seed rows and relationships through GraphQL
test_lake.py lake row counts and seed values through Trino
test_streams.py every row on its outbound topic; one record through every interface
```
The CLI applies `ods/*.sql` and `lakehouse/*.sql` in filename order, so extra files can be
@@ -103,6 +110,10 @@ the ODS. A GraphQL update came out on the compacted outbound topic and reached
role. `undeploy` also removed the registry group, which the management zone's Apicurio
allows.
Its unit tests passed the same day: 12 passed, and the relationship test was skipped because a
single-entity product has none. `canonical-party` in semprini-domain-cdp-digital-core, generated
from this template, passes 65 of 65 checks and 100 unit tests in about a minute.
The earlier verification, from semprini-blog-dataproducts:
On 2026-09-08 that round trip verified, on the live stack: the product's GraphQL endpoint
@@ -205,6 +216,8 @@ File | Source in the model
`flink/job.sql` | same columns as the table, Flink types
`lakehouse/010_replication.sql`, `trino/smoke.sql` | table names only
`odps.yaml` | product description, `sla`, `refresh`, governance posture, owner
`ods/040_seed.sql` | two or three rows per table with fixed uuids that satisfy every constraint
`tests/expectations.yaml` | the seed (row counts, one sample row per table), each constraint in `020_tables.sql` (an update that breaks it and the name PostgreSQL reports), every relationship field in `schema.graphql`, and one valid record for a table without required foreign keys
Rules that are easy to miss:
@@ -236,6 +249,69 @@ at `http://localhost:8081/apis/registry/v3` unless `APICURIO_URL` says otherwise
CLI substitutes it from `.env` when submitting the job, then deletes the rendered copy
from the jobmanager. Only `DOMAIN` and `ODS_PASSWORD` are substituted.
## Unit tests
`data-domain test` asks whether each interface is up. The unit tests ask whether the product
behaves as the model says, against the seed data in `ods/040_seed.sql`. Run them from the domain
repository after `deploy`:
```bash
uv run data-domain unit products/<slug> # all of them
uv run data-domain unit products/<slug> -k graphql # any pytest arguments after the path
```
The test modules are generic and copied unchanged into every product; only
`tests/expectations.yaml` is generated. The fixtures they use (`dp`, `product`, `expectations`)
come from the domain platform's pytest plugin, `semprini_data_domain.testing`, which reaches the
ODS and lakehouse with psql in their containers, GraphQL through PostgREST, the lake through
Trino's HTTP protocol and Kafka with a client on the domain's published port.
| Module | Checks, per table unless noted |
|---|---|
| `test_seed.py` | the seed row count; every sample row's values in the ODS |
| `test_constraints.py` | each `rejects` update to the first sample fails with the named constraint; an update moves `updated_at` past `created_at` |
| `test_graphql.py` | the GraphQL type has a field for every ODS column; sample rows through GraphQL; each relationship query's `expect` (whole product) |
| `test_lake.py` | the lake has as many rows as the ODS; sample rows through Trino |
| `test_streams.py` | every ODS key has a live value on the outbound topic; one `round_trip` record: inbound topic → ODS → outbound topic and lake → GraphQL update → both → GraphQL delete → tombstone and lake removal (whole product) |
The tests leave the seed as they found it: constraint checks run in a transaction that is rolled
back, and the round-trip record is deleted in a `finally` block. Before publishing that record,
`test_streams.py` inserts it into the ODS inside a rolled-back transaction. If the ODS refuses
it, the test fails there, and the record is never published, because a refused record stops the
Flink job (see *Platform prerequisites and known gaps*).
## Registering in the management zone
Once deployed and tested, publish the product in the management zone's catalogue:
```bash
uv run data-domain register products/<slug>
uv run data-domain unregister products/<slug>
```
The domain must be registered first (`platform/domain-integration.sh register mgmt`). That puts
the domain in OpenMetadata and the ingestion-bot token in the domain's `.env`. Then `register`
publishes:
- the lake tables under the domain's Trino service, with columns, descriptions and keys from the
ODS;
- the topics under the domain's Kafka service, with their JSON Schemas;
- the data product, imported from `odps.yaml`, with tables and topics as assets. Tables and
outbound topics are output ports, and inbound topics are input ports;
- lineage from each inbound topic to its table, and from the table to its outbound topic.
Apicurio needs no separate step: `deploy` registers the schemas there.
What this means for `odps.yaml`:
- **Keep it standard ODPS.** The platform translates it to the flattened shape OpenMetadata 2.0
imports.
- **Tags are dropped on import.** OpenMetadata would need every `details.tags` value to exist
as a classification tag, and the entity names used here are already the product's assets.
- **The name must be unique across domains.** OpenMetadata names the product from
`details.en.name` with spaces as underscores. `register` refuses to merge into a same-named
product in another domain.
- **Lifecycle isn't imported.** It starts at `DEVELOPMENT`, whatever `status` says, because
OpenMetadata's governance workflow owns it.
## Experience products read canonical ones
An experience product (MD-DDL `consumer-aligned`) is shaped for an audience rather than