BE-DP-01 · v1's duplicate VINs, from the v1 copy
ID BE-DP-01 · Level L0 · Pack Pack G2 · The schema the data phase maps v1 onto · Run order row 0a, first: before pack G2's pull request is merged · Issue #162
You know how many of v1's cars share a VIN, and which unit ids they are, posted on #162. Pack G2 makes a VIN unique within the organization (D47, R-VEH-26), so the data phase's vehicles step must know v1's duplicates before it loads a car: each one is cleaned in v1, or recorded as an unmatched row or an accepted difference (D18). It doesn't gate G2's merge (the CTO on #162).
No agent reads v1's data. This step reads only your local copy of v1, and changes nothing in it.
Before
Section titled “Before”- The v1 copy is restored in the
v1copycontainer on your Mac: BE-DP-06, in pack R1 (#184). docker ps --filter name=v1copylists the container as Up.- Never run this against v1 itself, staging or production: every block below goes to the copy through
docker exec v1copy.
1 · Where v1 keeps the VIN: columns whose name looks like one
Section titled “1 · Where v1 keeps the VIN: columns whose name looks like one”docker exec -i v1copy psql -U postgres -d postgres -c "select table_name, column_name, data_type from information_schema.columns where table_schema = 'public' and column_name ~* '(vin|rangka|chassis|frame)' order by 1, 2"2 · The same, inside v1's jsonb columns, with how many rows carry each key
Section titled “2 · The same, inside v1's jsonb columns, with how many rows carry each key”docker exec -i v1copy psql -U postgres -d postgres <<'SQL'do $$declare c record; k record;begin for c in select table_name, column_name from information_schema.columns where table_schema = 'public' and data_type = 'jsonb' order by 1, 2 loop for k in execute format( 'select jk.name, count(*) as n from public.%I, jsonb_object_keys(case when jsonb_typeof(%I) = ''object'' then %I end) as jk(name) ' 'where jk.name ~* ''(vin|rangka|chassis|frame)'' group by jk.name order by jk.name', c.table_name, c.column_name, c.column_name) loop raise notice '%.% -> % (% rows)', c.table_name, c.column_name, k.name, k.n; end loop; end loop;end $$;SQL3 · The duplicates
Section titled “3 · The duplicates”From blocks 1 and 2, pick v1's table of cars (the one with unit_id) and the expression that reads its VIN: a column such as no_rangka, or a jsonb key such as data ->> 'no_rangka'. A view that block 1 found, such as v_vehicle_master, works as the table too: it reads the same rows. To see what it calls the car's unit id, list its columns, names only:
docker exec -i v1copy psql -U postgres -d postgres -c "select column_name from information_schema.columns where table_schema = 'public' and table_name = '<V1_CARS_TABLE>' order by ordinal_position"Put them in place of the three placeholders, then run it. It prints counts, then one row per VIN that more than one car carries, with those cars' unit ids. VINs are compared in upper case without spaces or dashes, and an empty value or a dash counts as no VIN, as v2 will store it.
docker exec -i v1copy psql -U postgres -d postgres <<'SQL'with cars as ( select (<UNIT_ID_EXPRESSION>)::text as unit_id, nullif(nullif(upper(regexp_replace(coalesce((<VIN_EXPRESSION>)::text, ''), '[\s-]', '', 'g')), ''), '-') as vin from public.<V1_CARS_TABLE>),dup as ( select vin, count(*) as cars, string_agg(unit_id, ', ' order by unit_id) as unit_ids from cars where vin is not null group by vin having count(*) > 1)select 'cars' as what, count(*)::text as value from carsunion all select 'cars with a VIN', count(vin)::text from carsunion all select 'VINs on more than one car', count(*)::text from dupunion all select 'cars sharing a VIN', coalesce(sum(cars), 0)::text from dupunion all select 'unit ids sharing one VIN', unit_ids from dup;SQLExpect
Section titled “Expect”- Block 1: zero or a few rows, such as
units | no_rangka | text. Views count too:v_vehicle_master | no_rangka | textmeans the view reads the VIN for you, from a table's column or jsonb. Note the table or view, and the column. - Block 2:
NOTICElines such asunits.data -> no_rangka (812 rows), or none if v1 keeps the VIN in a column. - Block 3: four count rows, then one
unit ids sharing one VINrow per duplicate, such asU-0102, U-0417. No duplicate means the third and fourth counts read0and no unit id rows follow.
Post on #162: the table and the VIN expression you used, the four counts, and the unit id rows. Unit ids and counts only: never a VIN, a plate, a name or a phone from the copy (D15).
If it fails
Section titled “If it fails”- Block 2 stops with
column reference "key" is ambiguous: you ran the block as it was before 2026-10-21. Copy it again from this page. - Block 1 and block 2 find nothing: v1 may not store a VIN at all, or names it differently. Post the list of v1's tables (
\dt public.*) on #162, without any rows, and stop. - Block 3 fails with "column … does not exist" or "operator does not exist": a placeholder doesn't match the table. Fix it from blocks 1 and 2 and run it again; it only reads.
- Several candidate columns: run block 3 once for each, and post each result with its expression.
Nothing to undo: every block only reads the copy. The copy itself is removed as row 1 says, with docker rm -f v1copy and the dump deleted, when the data phase no longer needs it.
Log each run as a comment on #162: date · who · result · notes, with the output the Check names.