Skip to content

BE-DP-38 · The operations step on the local stack

ID BE-DP-38 · Level L0 · Pack Row 5 · The domain steps · Run order row 5, after the operations step (be/304-operations-step) is on integration · Issue #304

A night on your local stack, against the real v1 copy, runs master data, vehicles, drivers and rentals, then the operations step, and reconciles them. The operations step loads, from v1:

  • checkpoints as inspections (R-INSP-16 to R-INSP-19). Each finds its rental by lead and plate (R-INSP-17), and its nota becomes checklist items, with the whole nota kept in legacy_data.
  • preparation as preparation inspections, linked to the car's work order that day (R-INSP-21).
  • work_orders with their history as events (R-WO-10 to R-WO-12), and v1's reason as free text in legacy_reason (R-WO-14).
  • maintenance as maintenance records (R-WO-13).
  • asuransi_claims as claims, with their insurer and garage pairs (R-ASR-13 to R-ASR-15).
  • etle as violations, with their rental and payer (R-ETLE-06 to R-ETLE-08).
  • Stock Opname's one session and its expected cars (R-OPN-11 to R-OPN-14).
  • vehicle_status_log as status history (R-VEH-31).

v1's gate_logs and exit_tickets load nothing: the gate wasn't in use, so its logs are test data, and both tables are signed as ignored (R-GATE-14; zuki on #304, 2026-11-03). Gate passes start in v2. A row it can't place is an unmatched row with its reason (R-MIG-04), never a guess. It bills nothing and changes no car's status.

Block 1's values are mapped. The first night, on the copy of 2026-11-03, stopped at block 1 on 23 values no earlier read had shown: typeLaka, one return reason, ETLE's violation types and the first words of the work order history. zuki accepted their rows on #439 (2026-11-03). A history entry whose meaning its first word doesn't give loads as a note, with its text kept (R-WO-12). A value v1 adds after that copy still stops the night: post it on #304.

The second night's stop is fixed. Run 2 on the same copy stopped in the operations step, while it loaded inspections, on inspections_legacy_data_no_inline_files (R-STO-05): 4 of 7,772 checkpoints hold a file inline in their nota, one each in ttdPemeriksa, selfieDriver, fotoOdometer and bodyDiagram, where every other nota holds a file reference. The step now keeps each such value as the marker inline file not loaded (R-INSP-19), at any depth of the nota, and drops the driver's keys nama, ktp and tlp; selfieDriver and ttdUser stay as file references (zuki on #304, 2026-11-03). The checklist items are still read from v1's nota as it is. The reconcile's operations nota inline files prints how many loaded checkpoints had one (LED-OPS-01).

legacy and the loaded rows are a copy of v1's data in your local database: personal data, as the dump is (D15). The counts below are safe to post. The reconcile's lines and the unmatched rows name v1 ids and unit codes, so they stay on your Mac.

  • You are at the root of your clone, on integration with this step merged, after git pull, pnpm supabase db reset and BE-DP-07.
  • docker ps --filter name=v1copy lists the copy as Up, restored on the day you run.
  • BE-DP-36 has run on this copy. The operations step refuses to run unless master_data, vehicles, drivers and rentals ran in the same run, so block 2 runs all five.

Once this page's Before holds, this runs every block below and compares the counts with be-dp-38.expect, beside this page. It keeps each block's full output in ../opleet-private, prints block names, counts and error keys only (D15), and ends the run itself: succeeded only when no count changed.

Terminal window
python3 tools/migration/night.py local be-dp-38

Post what it prints under "To post on the issue". A changed or new line goes on the issue, not into this page; once it's accepted, ../opleet-private/be-dp-38-counts.txt replaces be-dp-38.expect. The blocks below stay for a rerun block by block.

1 · A run, its snapshot, and what's unmapped

Section titled “1 · A run, its snapshot, and what's unmapped”
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select migration.begin_run('BE-DP-38, local, on the v1 copy, with operations') as run;
select migration.snapshot() as tables_copied;
select domain, field, v1_value, rows from migration.unmapped_values() order by 1, 2, 3;
SQL

The insurer and garage names are checked only after master_data has loaded them. Once the list above is empty, run that step and read the list again (block 2 runs it again, which loads nothing more):

Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select migration.run('master_data') as master_rows;
select domain, field, v1_value, rows from migration.unmapped_values()
where field in ('asuransi_claims.data->asuransi', 'asuransi_claims.data->bengkel') order by 1, 2, 3;
SQL

If either list prints a line, stop. End the run with docker exec supabase_db_opleet psql -qX -U postgres -d postgres -c "select migration.finish_run('failed')" and post the lines on #304. Before you post, check each v1_value is a label or a code and not a person's name. Post a value only if 3 or more rows share it, and count the rest as "(other)".

Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select migration.run('master_data') as master_rows;
select migration.run('vehicles') as vehicle_rows;
select migration.run('drivers') as driver_rows;
select migration.run('rentals') as rental_rows;
select migration.run('operations') as operation_rows;
select table_name, (new_data ->> 'rows')::int as rows from public.audit_log
where action = 'migrated' and record_id = (select max(id) from migration.runs)::text
and new_data ->> 'step' = 'operations' order by id;
SQL
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
-- Unmatched, by table and reason.
select v1_table, reason, count(*) as rows from migration.unmatched
where run_id = (select max(id) from migration.runs) and step = 'operations' group by 1, 2 order by 1, 3 desc;
-- Inspections by kind, and how many have a rental (R-INSP-16, R-INSP-17, R-INSP-21).
select i.kind, count(*) as inspections, count(i.rental_id) as with_rental, count(i.work_order_id) as with_work_order
from public.inspections i join migration.id_map m on m.v2_id = i.id and m.entity in ('inspection', 'preparation_inspection')
group by 1 order by 1;
select i.return_reason, count(*) from public.inspections i where i.kind = 'return' group by 1 order by 2 desc;
select i.outcome, count(*) from public.inspections i where i.kind = 'preparation' group by 1 order by 1;
-- Checklist rows by grade, and equipment by present (R-INSP-19).
select it.grade, it.present, count(*) as items, count(*) filter (where it.note = '-') as marked_from_v1
from public.inspection_items it group by 1, 2 order by 1, 2;
-- Work orders by status and route, and their events (R-WO-10, R-WO-12).
select status, route, count(*) as work_orders, count(inspection_id) as with_return from public.work_orders group by 1, 2 order by 1, 2;
select action, count(*) as events from public.work_order_events group by 1 order by 1;
-- Maintenance by kind and mode (R-WO-13).
select kind, mode, count(*) as records, count(work_order_id) as with_work_order, count(*) filter (where completed_on is null) as no_end
from public.maintenance_records group by 1, 2 order by 1, 2;
-- No gate pass or approval from v1 (R-GATE-14): both 0.
select (select count(*) from public.gate_passes) as gate_passes, (select count(*) from public.gate_pass_approvals) as approvals;
-- Claims by status, with an insurer, and the pairs (R-ASR-13 to R-ASR-15).
select status, count(*) as claims, count(insurer_id) as with_insurer from public.insurance_claims group by 1 order by 1;
select count(*) as insurer_garage_pairs from public.insurer_garages;
-- ETLE by status and payer (R-ETLE-06 to R-ETLE-08).
select status, payer, count(*) as violations, count(rental_id) as with_rental from public.etle_violations group by 1, 2 order by 1, 2;
-- Stock Opname (R-OPN-14) and status history (R-VEH-31).
select s.status, count(x.id) as expected, count(*) filter (where x.scanned) as scanned
from public.stock_opname_sessions s left join public.stock_opname_expected x on x.session_id = s.id group by 1;
select count(*) as history_rows, count(*) filter (where from_status is null) as first_status from public.vehicle_status_history;
SQL
Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select check_name, count(*) as lines from migration.reconcile() group by 1 order by 1;
SQL
mkdir -p ../opleet-private
docker exec supabase_db_opleet psql -qX -U postgres -d postgres -c "select * from migration.reconcile() where check_name like 'operations%' or check_name = 'unmatched rows' or check_name = 'v1 unclaimed'" > ../opleet-private/reconcile-be-dp-38.txt
wc -l ../opleet-private/reconcile-be-dp-38.txt

The file holds v1 ids and unit codes; it stays on your Mac.

Two signed prints count rows rather than list them (R-VEH-31, R-WO-13). Their rows, for you to look at locally:

Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL' > ../opleet-private/lists-be-dp-38.txt
-- R-VEH-31: the cars whose status isn't their latest v1 history row's.
select v.unit_code, v.status, h.to_status as latest_history_to
from public.vehicles v
cross join lateral (select x.to_status from public.vehicle_status_history x
join migration.id_map m on m.v2_id = x.id and m.entity = 'vehicle_status'
where x.vehicle_id = v.id order by x.changed_at desc, x.id desc limit 1) h
where v.status <> h.to_status order by 1;
-- R-WO-13: the maintenance records loaded with no end date, by v1 id.
select m.v1_key, r.kind, r.started_on
from public.maintenance_records r join migration.id_map m on m.v2_id = r.id and m.entity = 'maintenance'
where r.completed_on is null order by 1;
SQL
wc -l ../opleet-private/lists-be-dp-38.txt

That file holds unit codes and v1 ids too; it stays on your Mac.

Terminal window
docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'
select row_key, detail from migration.reconcile()
where check_name = 'v1 unclaimed'
and row_key ~ '^(table|column) (checkpoints|preparation|work_orders|maintenance|gate_logs|asuransi_claims|etle|exit_tickets|stock_opname_\w+|vehicle_status_log)\y'
order by 1;
-- The prints and the stock opname difference, read from the checks: zuki signed them, so the reconcile hides them.
select 'inspection rentals' as print, * from migration.check_operations('rentals')
union all select 'no work order', * from migration.check_operations('no_work_order')
union all select 'preparation not checked', * from migration.check_operations('not_checked')
union all select 'etle payer', * from migration.check_operations('etle_payer')
union all select 'etle driver unknown', * from migration.check_operations('etle_driver')
union all select 'nota inline files', * from migration.check_operations('nota_files')
union all select 'stock opname counts', * from migration.check_operations('opname')
union all select 'status history', * from migration.check_operations('status_history')
union all select 'maintenance open', * from migration.check_operations('maintenance_open')
order by 1, 2;
SQL
Terminal window
docker exec supabase_db_opleet psql -qX -U postgres -d postgres -c "select migration.finish_run('succeeded')"

The counts are zuki's clean night of 2026-11-04 on the copy of 2026-11-03 (#304). v1 moves (D75): on a later copy, a difference goes on #304, not into this page.

  • Block 1: a run id, tables_copied 45, and no unmapped line, before or after master_data (insurers and garages included).
  • Block 2: the four earlier steps load what BE-DP-36 loads (0 if this database already holds them). The operations step loads 280,914 rows, one audit line per table: inspection_item_types 33, inspections 7,772, inspection_items 252,660, work_orders 1,515, work_order_events 5,901, inspections (preparation) 1,067, maintenance_records 708, insurer_garages 38, insurance_claims 189, etle_violations 226, stock_opname_sessions 1, stock_opname_expected 111 and vehicle_status_history 10,693. No gate pass or approval (R-GATE-14).
  • Block 3:
    • Inspections: checkpoint 4,303, handover 2,028, return 1,441 and preparation 1,067. With a rental: 3,006, 1,178 and 73 (R-INSP-17). 848 preparations have a work order.
    • Return reasons: on_leave 685, repossessed 476, resigned 94, accident 77, suspended 62, breakdown 46, contract_ended 1.
    • Preparation outcomes: ok 1,017, needs_maintenance 26, needs_insurance 24.
    • Work orders: 1,515: ready 1,415, routed 93, waiting 7, with the Ready work order with no readyAt taking its ready time from its history (R-WO-18). Events: opened 1,515, routed 1,274, ready 1,411, note 1,701.
    • Maintenance: 708, 112 with a work order, 10 with no end date.
    • Gate passes and approvals: 0 and 0 (R-GATE-14).
    • Claims: 189: done 99, in_repair 24, submitted 66. With an insurer 107. Insurer and garage pairs: 38.
    • ETLE: 226.
    • Stock Opname: one void session with 111 expected cars, 0 scanned.
    • Status history: 10,693 rows, 1,823 of them a car's first status.
  • Block 4: the reconcile holds only BE-DP-36's 8 checks, with unmatched rows at BE-DP-36's count: 46 (47 at 7178ad1, before R-WO-18, LED-OPS-02); a work order listed with that reason has no timed Ready entry in its history either: post it. No operations line prints: operations inspections per kind, operations checkpoints per month, operations work orders per status, operations claims per status, operations last checkpoint, operations inspection values and operations work order events are empty, and the signed lines (block 5) are hidden. The local lists: 113 cars and 10 maintenance records.
  • Block 5: no unclaimed line for these tables. The four columns the step leaves unread (checkpoints.lite_nama_driver, stock_opname_expected.vehicle, stock_opname_sessions.assigned and stock_opname_sessions.started_by) and the table exit_tickets are signed (zuki, #439, 2026-11-03), and so is the table gate_logs (R-GATE-14; zuki, #304, 2026-11-03). A new v1 column on one of these tables would show here. The prints are one line per kind, per table or per billing status, and zuki signed each of them on #304 (2026-11-03), with the stock opname difference, so the reconcile hides them while block 5 still reads them from the checks. The 14 signed lines that night, by check: inspection rentals 3,006, 1,178 and 73 with a rental; no work order 596 maintenance, 219 preparation and 9 of 1,441 return inspections; preparation not checked 2; etle payer 1 of 2 Ditanggung Fleet and 27 of 78 Lunas Driver; etle driver unknown 4; nota inline files 4; stock opname counts session void, v1 111, 0 and 0 against v2 111, 0 and 111; status history 113 cars; maintenance open 10 records. A signature never covers a count, so post the counts: a change shows here, not in the reconcile.

Post on #304: the date of the copy, block 1's lines (labels and counts), block 2's numbers, block 3's counts, block 4's lines per check (counts only), and what you sign from block 5.

pnpm supabase db reset, then BE-DP-07. The copy and the dump are untouched.