Skip to content

Commit a2572cd

Browse files
fix(dv2): rename record_source example x5__* -> mp__* (B2) (#139)
The governance admission logic (audit_28_06_26 #12) proves it is source-agnostic by citing a third record_source convention alongside 1c__/pg_ops__. That example carried the name of the Kaggle seed dataset (X5 Retail Hero); under the legend (domain.md §5.3-5.4) it is the consolidated marketplace feed, mp__. Renamed in the 5 ClickHouse bv_customer_mdm__* view headers, the PostgreSQL port (03_business_vault.sql), the PostgreSQL governance live-verify seed literal (the one place x5__ was an actual value, not just prose), and both admission-test docstrings. Added a ratchet assertion to each admission test (checked on raw text, since the example lives in a header comment that the tests otherwise strip). domain.md §5.3/§5.4 updated to reflect the rename is done. x5__ was never a real record_source value in the generator/seeds (those emit 1c__/pg_ops__/wb__) -- it only existed as documentation vocabulary for this one audit story. Co-authored-by: JuliaEdom <uedomskikh@gmail.com>
1 parent 4437e9c commit a2572cd

10 files changed

Lines changed: 45 additions & 22 deletions

File tree

‎docs/domain.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ renames. The two exceptions are listed in §5.4.
197197
| `wb__` | Wildberries seller API | FBS orders, commissions, returns |
198198
| `excel__` | Logistics spreadsheets | Container manifests, cross-dock — the inbound-container storyline |
199199
| `pg_ops__` | Postgres OLTP (hot tier) via CDC | Operational order/customer rows promoted into the vault |
200-
| `mp__` (currently `x5__`) | Consolidated marketplace order feed | High-volume retail order history (see §5.4) |
200+
| `mp__` | Consolidated marketplace order feed | High-volume retail order history |
201201

202202
### 5.4 Planned renames / repins (the only code changes the legend requires)
203203

204204
| Change | Scope | Status |
205205
| ------ | ----- | ------ |
206-
| `x5__*` → `mp__*` record_source (+ governance SQL, officer probes, admission tests) | The prefix currently carries the name of the Kaggle seed dataset (X5 Retail Hero) that the demo loader replays as transaction history. Under the legend it is the **consolidated marketplace feed**, and the prefix should say so. Dataset attribution stays in the loader README | Planned (data phase) |
206+
| `x5__*` → `mp__*` record_source (+ governance SQL, officer probes, admission tests) | The prefix carried the name of the Kaggle seed dataset (X5 Retail Hero) that the demo loader replays as transaction history. Under the legend it is the **consolidated marketplace feed**, and the prefix says so. Dataset attribution stays in the loader README | **Done** (B2) |
207207
| Demo value repin: currencies to `RUB` (primary), `AED`/`KZT` in branch stories; demo revenue/counts consistent with §1–2 | `contracts/entities/order.yaml` currency examples, NL demo answers, seeded `ORD-*` rows | Planned (data phase, after the generator spec) |
208208

209209
Vocabulary guardrails for all public docs: the company is an **own-brand /

‎tests/unit/test_dv2_business_vault_ddl.py‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
this file. It pins that every view parses under sqlglot's ClickHouse dialect and
55
that the customer MDM views admit hub rows by branch via
66
``splitByString('__', record_source)[2]`` — NOT by a hard-coded
7-
``record_source = '1c__<branch>'`` filter that silently dropped OLTP/X5-promoted
8-
customers (``record_source`` ``pg_ops__`` / ``x5__``).
7+
``record_source = '1c__<branch>'`` filter that silently dropped OLTP/marketplace-
8+
promoted customers (``record_source`` ``pg_ops__`` / ``mp__``).
99
1010
This is the ClickHouse half of audit_28_06_26 #12. The PostgreSQL port was fixed
1111
in ``test_dv2_postgres_ddl.py::test_customer_mdm_views_admit_all_source_conventions``;
@@ -59,15 +59,17 @@ def test_customer_mdm_views_admit_all_source_conventions():
5959
"""audit_28_06_26 #12 (ClickHouse half): the customer MDM views must select
6060
hub rows by branch via ``splitByString('__', record_source)[2]``, NOT by a
6161
hard-coded ``record_source = '1c__<branch>'`` filter that silently drops
62-
OLTP/X5-promoted customers (record_source ``pg_ops__`` / ``x5__``). Proven
63-
live on PostgreSQL in #99: the buggy filter returns 1 of 2 seeded customers,
64-
the source-agnostic filter returns both. This keeps the ClickHouse views in
65-
lock-step with the PostgreSQL port so the engines cannot diverge again."""
62+
OLTP/marketplace-promoted customers (record_source ``pg_ops__`` / ``mp__``).
63+
Proven live on PostgreSQL in #99: the buggy filter returns 1 of 2 seeded
64+
customers, the source-agnostic filter returns both. This keeps the
65+
ClickHouse views in lock-step with the PostgreSQL port so the engines
66+
cannot diverge again."""
6667
for branch in MDM_BRANCHES:
6768
path = BV_DIR / f"bv_customer_mdm__{branch}.sql"
6869
# Strip block/line comments: the headers deliberately quote the old,
6970
# buggy ``record_source = '1c__<branch>'`` filter to explain the fix.
70-
body = _strip_comments(path.read_text(encoding="utf-8"))
71+
raw = path.read_text(encoding="utf-8")
72+
body = _strip_comments(raw)
7173
assert f"CREATE OR REPLACE VIEW rv.bv_customer_mdm__{branch}" in body, (
7274
f"bv_customer_mdm__{branch}.sql must define rv.bv_customer_mdm__{branch}"
7375
)
@@ -80,3 +82,13 @@ def test_customer_mdm_views_admit_all_source_conventions():
8082
f"hard-coded record_source = '1c__<branch>' filter in "
8183
f"bv_customer_mdm__{branch} reintroduces audit #12"
8284
)
85+
# B2 (domain.md §5.4): the legend's marketplace-feed vocabulary replaces
86+
# the Kaggle dataset name in the third-source-convention example (checked
87+
# on the RAW text — the example lives in the header comment, which body
88+
# strips).
89+
assert "x5__" not in raw, (
90+
f"stale Kaggle-dataset record_source prefix x5__ leaked back into bv_customer_mdm__{branch}.sql"
91+
)
92+
assert "mp__" in raw, (
93+
f"bv_customer_mdm__{branch}.sql should document the mp__ marketplace-feed convention (domain.md §5.3)"
94+
)

‎tests/unit/test_dv2_postgres_ddl.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ def test_business_vault_uses_postgres_collapse():
147147
def test_customer_mdm_views_admit_all_source_conventions():
148148
"""audit_28_06_26 #12: the customer MDM views must select hub rows by
149149
branch via split_part(record_source, '__', 2), NOT by a hard-coded
150-
record_source = '1c__<branch>' filter that silently drops OLTP/X5-promoted
151-
customers (record_source pg_ops__/x5__). Proven live on PG: the buggy filter
152-
returns 1 of 2 seeded customers, the split_part filter returns both."""
153-
body = _strip_comments((PG_DIR / "03_business_vault.sql").read_text(encoding="utf-8")).lower()
150+
record_source = '1c__<branch>' filter that silently drops OLTP/marketplace-
151+
promoted customers (record_source pg_ops__/mp__). Proven live on PG: the
152+
buggy filter returns 1 of 2 seeded customers, the split_part filter returns
153+
both."""
154+
raw = (PG_DIR / "03_business_vault.sql").read_text(encoding="utf-8").lower()
155+
body = _strip_comments(raw)
154156
branches = ("msk", "spb", "ekb", "dxb", "ala")
155157
for branch in branches:
156158
assert f"view rv.bv_customer_mdm__{branch}" in body, f"missing PG view for {branch}"
@@ -161,6 +163,15 @@ def test_customer_mdm_views_admit_all_source_conventions():
161163
assert "record_source = '1c__" not in body, (
162164
"hard-coded record_source = '1c__<branch>' filter reintroduces audit #12"
163165
)
166+
# B2 (domain.md §5.4): the legend's marketplace-feed vocabulary replaces the
167+
# Kaggle dataset name in the third-source-convention example (checked on the
168+
# RAW text — the example lives in the header comment, which body strips).
169+
assert "x5__" not in raw, (
170+
"stale Kaggle-dataset record_source prefix x5__ leaked back into 03_business_vault.sql"
171+
)
172+
assert "mp__" in raw, (
173+
"03_business_vault.sql should document the mp__ marketplace-feed convention (domain.md §5.3)"
174+
)
164175

165176

166177
def test_hubs_and_links_have_bytea_primary_keys():

‎warehouse/agentflow/dv2/business_vault/bv_customer_mdm__ala.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Purpose: Canonical customer record for the ALA branch.
33
Layer: Business Vault.
44
Branch: ala (KZ jurisdiction; Bitrix loyalty not wired in ALA).
55
Hub admission: splitByString('__', record_source)[2] = 'ala' (source-agnostic:
6-
1c__/pg_ops__/x5__ all integrated, not only 1C; audit_28_06_26 #12;
6+
1c__/pg_ops__/mp__ all integrated, not only 1C; audit_28_06_26 #12;
77
mirrors the PostgreSQL port's split_part(record_source,'__',2)).
88
Security: SQL SECURITY DEFINER (ADR 0006 Phase 2) — readers query this view
99
under the definer's rights, so the column-limited grants in

‎warehouse/agentflow/dv2/business_vault/bv_customer_mdm__dxb.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Conflict policy:
88
keeps the loyalty columns for schema parity with bv_customer_mdm__msk so
99
downstream marts can UNION ALL the two branches without renaming.
1010
Hub admission: splitByString('__', record_source)[2] = 'dxb' (source-agnostic:
11-
1c__/pg_ops__/x5__ all integrated, not only 1C; audit_28_06_26 #12;
11+
1c__/pg_ops__/mp__ all integrated, not only 1C; audit_28_06_26 #12;
1212
mirrors the PostgreSQL port's split_part(record_source,'__',2)).
1313
Security: SQL SECURITY DEFINER (ADR 0006 Phase 2) — readers query this view
1414
under the definer's rights, so the column-limited grants in

‎warehouse/agentflow/dv2/business_vault/bv_customer_mdm__ekb.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Purpose: Canonical customer record for the EKB branch.
33
Layer: Business Vault.
44
Branch: ekb (RU jurisdiction; same conflict policy as MSK).
55
Hub admission: splitByString('__', record_source)[2] = 'ekb' (source-agnostic:
6-
1c__/pg_ops__/x5__ all integrated, not only 1C; audit_28_06_26 #12;
6+
1c__/pg_ops__/mp__ all integrated, not only 1C; audit_28_06_26 #12;
77
mirrors the PostgreSQL port's split_part(record_source,'__',2)).
88
Security: SQL SECURITY DEFINER (ADR 0006 Phase 2) — readers query this view
99
under the definer's rights, so the column-limited grants in

‎warehouse/agentflow/dv2/business_vault/bv_customer_mdm__msk.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Conflict policy:
99
- If a customer exists only in Bitrix, PII columns are NULL but the row
1010
is still returned so loyalty-only customers stay visible.
1111
Hub admission: splitByString('__', record_source)[2] = 'msk', so a customer
12-
promoted under ANY source convention (1c__msk, pg_ops__msk, x5__msk,
12+
promoted under ANY source convention (1c__msk, pg_ops__msk, mp__msk,
1313
...) is integrated, not only 1C. The old record_source = '1c__msk'
14-
filter silently dropped OLTP/X5-promoted customers (audit_28_06_26 #12);
14+
filter silently dropped OLTP/marketplace-promoted customers (audit_28_06_26 #12);
1515
this mirrors the PostgreSQL port's split_part(record_source,'__',2).
1616
Security: SQL SECURITY DEFINER (ADR 0006 Phase 2) — readers query this view
1717
under the definer's rights, so the column-limited grants in

‎warehouse/agentflow/dv2/business_vault/bv_customer_mdm__spb.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Purpose: Canonical customer record for the SPB branch.
33
Layer: Business Vault.
44
Branch: spb (RU jurisdiction; same conflict policy as MSK).
55
Hub admission: splitByString('__', record_source)[2] = 'spb' (source-agnostic:
6-
1c__/pg_ops__/x5__ all integrated, not only 1C; audit_28_06_26 #12;
6+
1c__/pg_ops__/mp__ all integrated, not only 1C; audit_28_06_26 #12;
77
mirrors the PostgreSQL port's split_part(record_source,'__',2)).
88
Security: SQL SECURITY DEFINER (ADR 0006 Phase 2) — readers query this view
99
under the definer's rights, so the column-limited grants in

‎warehouse/agentflow/dv2/postgres/03_business_vault.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ Dialect: postgresql.
144144
Branch: one view per jurisdiction by design — PII stays in branch.
145145
Hub admission: split_part(record_source,'__',2) = '<branch>', so a customer
146146
promoted under ANY source convention (1c__<branch>, pg_ops__<branch>,
147-
x5__<branch>, ...) is integrated. This mirrors bv_order_canonical's
147+
mp__<branch>, ...) is integrated. This mirrors bv_order_canonical's
148148
order_branch derivation above. The ClickHouse views hard-code
149149
record_source = '1c__<branch>', which silently dropped every OLTP- and
150-
X5-promoted customer (record_source pg_ops__/x5__) from the MDM result
150+
marketplace-promoted customer (record_source pg_ops__/mp__) from the MDM result
151151
(audit_28_06_26 #12). The hash keys were never incompatible —
152152
customer_hk = md5(business_key) is identical across loaders; only the
153153
hub record_source filter excluded them. split_part is the source-

‎warehouse/agentflow/dv2/postgres/governance/verify_live.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ INSERT INTO rv.hub_customer (customer_hk, customer_bk, record_source) VALUES
4949
(decode(md5('CUST-MSK-5'),'hex'),'CUST-MSK-5','1c__msk'),
5050
(decode(md5('CUST-MSK-6'),'hex'),'CUST-MSK-6','1c__msk'),
5151
(decode(md5('CUST-MSK-7'),'hex'),'CUST-MSK-7','pg_ops__msk'),
52-
(decode(md5('CUST-MSK-8'),'hex'),'CUST-MSK-8','x5__msk'),
52+
(decode(md5('CUST-MSK-8'),'hex'),'CUST-MSK-8','mp__msk'),
5353
(decode(md5('CUST-DXB-1'),'hex'),'CUST-DXB-1','1c__dxb'),
5454
(decode(md5('CUST-DXB-2'),'hex'),'CUST-DXB-2','1c__dxb')
5555
ON CONFLICT (customer_hk) DO NOTHING;

0 commit comments

Comments
 (0)