BE-DP-40 · The money step on the local stack
ID BE-DP-40 · Level L0 · Pack Row 5 · The domain steps · Run order row 5, after the money step (team/306-money-step) is on integration, with its account rows in · Issue #306
A night on your local stack, against the real v1 copy, runs master data, vehicles, drivers, rentals and operations, then the money step, and reconciles them. The money step loads, from v1:
billsas charges, one each, as v1 billed them (R-MON-84, R-MON-64, R-MON-65), each on its lead's rental by R-INSP-17's lookup (R-MON-85), with its company from its car, its driver'spref_akunor its own payments' accounts (R-MON-95, R-MON-96), and a Klaim Panel charge linked to its inspection (R-MON-83).- The instalments as payments and allocations (R-MON-54), with one driver's instalments of one proof, day and account as one payment (R-MON-77), and who confirmed a v1 payments row as a note on its payment (R-MON-97).
- One payment of
dibayarfor each Lunas bill with no instalment thatdibayarcovers (R-MON-60), and each confirmedpaymentsrow no instalment records (R-MON-58). - Rebates, then allocations, then refunds (R-MON-78), so a refund never reads as credit.
claim_lettersas issued debt letters (R-COL-09 to R-COL-21). Debts load no charge: the bill is the charge (R-MON-76).
A row it can't place is an unmatched row with its reason (R-MIG-04), never a guess. It bills nothing.
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 name v1 ids and hold one driver's amounts, so they stay on your Mac.
Before
Section titled “Before”- You are at the root of your clone, on
integrationwith this step merged, aftergit pull,pnpm supabase db resetand BE-DP-07. docker ps --filter name=v1copylists the copy as Up, restored on the day you run.- The money step's migration holds the rows for the accounts
rekTujuannames, keyed by their last four digits, andKwitansias cash (R-MON-90, R-MON-72). A value with no row stops block 1. So does a value ofvehicle_master.data.platformorpref_akunother than Gojek, Grab and Keduanya (R-MON-95, R-MIG-02). pnpm supabase test dbneeds a stack with no night loaded, so run it before this step or after a reset.
The night in one paste
Section titled “The night in one paste”Once this page's Before holds, this runs every block below and compares the counts with be-dp-40.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.
python3 tools/migration/night.py local be-dp-40Post 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-40-counts.txt replaces be-dp-40.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”docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'select migration.begin_run('BE-DP-40, local, on the v1 copy, with money') as run;select migration.snapshot() as tables_copied;select domain, field, v1_value, rows from migration.unmapped_values() order by 1, 2, 3;SQLIf it 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 #306. An account's line prints its last four digits, or the words left once the holder's text is stripped: check it holds no name before you post it.
2 · The six steps
Section titled “2 · The six steps”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 migration.run('money') as money_rows;select table_name, (new_data ->> 'rows')::int as rows from public.audit_logwhere action = 'migrated' and record_id = (select max(id) from migration.runs)::text and new_data ->> 'step' = 'money' order by id;SQL3 · The counts
Section titled “3 · The counts”docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'-- Unmatched, by table and reason (the letter duplicate's reason is shortened: it names a number).select v1_table, regexp_replace(reason, 'letter .*$', 'letter') as reason, count(*) as rows from migration.unmatchedwhere run_id = (select max(id) from migration.runs) and step = 'money' group by 1, 2 order by 1, 3 desc;-- Charges by type and status, with a rental and a billing day (R-MON-84, R-MON-85, R-MON-86).select t.code, c.status, count(*) as charges, sum(c.amount) as amount, count(c.rental_id) as with_rental, count(c.billing_day) as with_day, count(c.legal_entity_id) as with_entity, count(c.inspection_id) as with_inspectionfrom public.charges c join public.charge_types t on t.id = c.charge_type_id group by 1, 2 order by 1, 2;-- Payments by source and method (R-MON-55, R-MON-72).select migrated_from, method, count(*) as payments, sum(amount) as amount, count(bank_account_id) as with_account, count(*) filter (where voided_at is not null) as voidedfrom public.payments group by 1, 2 order by 1, 2;-- Allocations and adjustments (R-MON-78).select count(*) as allocations, sum(amount) as allocated from public.payment_allocations;select kind, count(*) as adjustments, sum(amount) as amount, count(*) filter (where reason = 'v1: no reason recorded') as no_reasonfrom public.charge_adjustments group by 1 order by 1;-- The balance, and the credit, over all drivers (R-MON-79, R-MON-92).select sum(open_balance) as open_balance, count(*) filter (where open_balance > 0) as drivers_owing from public.v_driver_balance;select sum(open) as open_of_record, sum(credit) as credit_of_record, count(*) filter (where credit > 0) as drivers_in_creditfrom migration.money_record where run_id = (select max(id) from migration.runs);-- Letters and their items (R-COL-09, R-COL-20).select status, count(*) as letters, count(rental_id) as with_rental from public.debt_letters group by 1;select count(*) as items, count(legacy_amount) as with_amount from public.debt_letter_items;-- R-MON-63: the migrated payments with no proof or account, expected by rule. Never signed.select * from migration.check_money('expected');SQL4 · The reconcile, by check
Section titled “4 · The reconcile, by check”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;SQLmkdir -p ../opleet-privatedocker exec supabase_db_opleet psql -qX -U postgres -d postgres -c "select * from migration.reconcile() where check_name like 'money%' or check_name = 'unmatched rows' or check_name = 'v1 unclaimed'" > ../opleet-private/reconcile-be-dp-40.txtwc -l ../opleet-private/reconcile-be-dp-40.txtThe file holds v1 ids and one driver's amounts; it stays on your Mac.
5 · What's left unclaimed
Section titled “5 · What's left unclaimed”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) (bills|payments|debts|claim_letters)\y' order by 1;SQL6 · The end of the run
Section titled “6 · The end of the run”docker exec supabase_db_opleet psql -qX -U postgres -d postgres -c "select migration.finish_run('succeeded')"Then run BE-DP-23, with this night's steps in its domain_steps, so the payment and rebate folders attach.
Expect
Section titled “Expect”These are run 2's counts, from the copy of 2026-11-05 (#306). v1 moves (D75): a difference goes on #306, not into this page.
- Block 1: a run id,
tables_copied55 or more, and no unmapped line. - Block 2: the five earlier steps load what BE-DP-38 loads. The money step loads 174,516 rows, and its audit lines are one per table it loaded, plus
etle_violations (charge link), the violations it linked, whose count adds to the rows (R-ETLE-09). Block 2 took 6 min 56 s, all six steps. If it passes 15 minutes, cancel it and post on #306 which statement the cancel's CONTEXT names. - Block 3:
- Unmatched: 143.
debts31 (R-MON-81).bills78: 1 due before its charge and 77 on leads the drivers step left out.claim_letters29: 8 with a debtId that names no bill, 7 with no one driver, 6 on left-out leads, 4 whose bill loaded no charge, 3 with no bill found and 1 duplicate.payments5. - Charges: 26,183 in all, one per bill.
with_entity25,162 (R-MON-95). Rent charges with a rental 1,587. - Payments: 72,442:
bills.data.pembayaran54,324,bills.data.dibayar18,116 andpayments2, the confirmed rows no instalment records (R-MON-58). Allocations 72,483. - Adjustments: refunds 161, rebates 141.
- Balance:
open_balanceequalsopen_of_recordto the rupiah. 57 drivers are in credit, and payments less allocations equals the credit of record exactly. - Letters: 1,170, all
issued. - Items:
with_amount1,843 of 1,934: R-COL-21 pairs by type. - ETLE link (R-ETLE-09): in
check_money('expected'),etle linkednear 237,etle unlinkednear 23 andetle several0, on the 260 rows of the copy of 2026-11-05. v1 moves (D75), so a small difference isn't a failure: a bill on a left-out lead loads no charge, so its row counts as unlinked. Those counts came from a read that matched loosely, in upper case with punctuation stripped, and this step's key is exact. So a linked count well below 237 meanssourceandno_tilangdiffer in form: post the three lines on #538 and stop.
- Unmatched: 143.
- Block 4:
money balance per driver,money credit per driver,money payments per day and account,money paid bills per dayandmoney allocationsprint no line, so each is 0; a line on any of them needs a look. The rest are the lists you sign or have fixed in v1:money pending payments327, with the Ignore rows, falling as finance clears them (R-MON-59),money lunas short57,money owed with dibayar1,money zero instalments38,money refund flag with no amount1,money refunds on bills not paid in full60,money debts of another amount1,money letters renumbered43,money letters whose text or plate disagree10,money letters on several leads32,money letters with another lead's item29,money charges with no company1,021, by v1 id (R-MON-96), andmoney violations with several bills0, by v1 id, never by ticket (R-ETLE-09). Five are one-line counts: charges with no rental, panel charges with no inspection, and letters with no plate, with no rental and not paired, which falls from run 1's 124 (R-COL-21). Across all the steps,unmatched rowsprints 226 lines: money 143, drivers 71, rentals 12.v1 unclaimedprints 32. - Block 5:
payments' 7 columns the step doesn't read print here:bukti,jenis,pic,plat,tgl_hari,edited_atandedited_by, less any another step claims. They are for you to sign or send back.
If it fails
Section titled “If it fails”- Block 1 prints a line: see block 1. The first night after R-MON-95 may stop here once:
vehicle_master.data->platformandleads.data->pref_akunhave rows only for Gojek, Grab and Keduanya, so any other value prints with its count. That first run is the list of values. Post the lines, zuki maps each (R-MIG-02), and the night runs again. migration.step_money: run the … steps first: run all six in one run, from block 2.allocation.exceeds_balanceorallocation.exceeds_payment: the step's arithmetic and the guard disagree. Stop, end the run as failed, and post theERRORline without its DETAIL, which holds one driver's amounts.- A
foreign keyerror onbank_account_id: avalue_maprow names an accountmigration.bank_accountsdoesn't have. Post the line. - Anything else: end the run as failed and post the
ERRORline. Read it first: drop any detail with a name or an amount.
pnpm supabase db reset, then BE-DP-07. The copy and the dump are untouched.
Log each run on #306: the date of the copy, block 2's numbers, block 3's counts, block 4's lines per check (counts only), and block 5's rows.