BE-DP-36 · The rentals step on the local stack
ID BE-DP-36 · Level L0 · Pack Row 5 · The domain steps · Run order row 5, after the rentals step's code (be/302-rentals-code) is on integration · Issue #302
A night on your local stack, against the real v1 copy, loads master data, vehicles, drivers and then the rentals step (D67, D69, D78, D82), and reconciles them. The rentals step loads:
- one rental for each onboarding row except On Process and the old-data rows, in the status D69 and D82 give it (R-RNT-32 to R-RNT-37, R-RNT-64);
- a chain of rentals for a driver whose rate changed (R-RNT-41), from
v_rental_fee_audit; - v1's contract on the live row of its rental, with the number its html prints (R-RNT-44) and the term v1 holds, or none (R-RNT-61);
- what v1 knew of each change and each contract, as
legacy_columns (D84): each chain row that begins at a fee change keeps that change'soleh,detail,plat_beforeandplat_afterinrentals.legacy_data(R-RNT-69), and each contract keeps v1'supdated_atinlegacy_updated_at(R-RNT-70). The rate-history rows the chain doesn't carry are counted in five kinds, not stored (R-RNT-72).
A row it can't place is an unmatched row with its reason (R-MIG-04), never a guess.
The values #369 asked for are signed: an empty deduction_frequency is daily (R-RNT-65) and an empty Listed flag is paused (R-RNT-36), as rows of value_map; the 33 old-data Approve rows are ignored and their drivers made inactive (R-RNT-64, R-DRV-55); and the one Listed row with an empty flag (v1 id 2155) loads nothing and is ignored on purpose (R-RNT-66). So block 1's unmapped list should be empty.
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 lead and onboarding ids, so they stay on your Mac.
This night's reconcile is not clean, on purpose. It lists the 297 cancelled rows and the unclaimed columns for you to sign (block 5), and whatever the unmatched rows are. Block 4 says which lines to expect. The counts marked "from the first run, BE confirms" were derived from the first local run of the step and are confirmed against your run, not promised.
Before
Section titled “Before”- You are at the root of your clone, on
integration(the rentals code merged), aftergit pull,pnpm supabase db resetand BE-DP-07. The reset removesv1_live, so you link it again. docker ps --filter name=v1copylists the copy as Up.v1_liveholds the rate history.export.sqlexports v1's viewv_rental_fee_auditas well as the tables. A stack linked before that change doesn't have it, and the rentals step then refuses (migration.step_rentals_no_rate_history) instead of loading no chains. Run BE-DP-06's block 5 (export.sql) again, then BE-DP-07, and checkforeign_tablesreads 35. Block 1 checks it again withrate_history.- BE-DP-26 and BE-DP-32 are logged: the rentals step needs the organization master data loads, the cars and the drivers. BE-DP-29 (the access step) is not needed: the rentals step doesn't read logins or menus. Block 6 uses BE-DP-23's inputs (the pooler login and the photo reader), so have them to hand only if you run it.
- The run repeats master_data, vehicles and drivers. The rentals step reads the run's
step_logand refuses to run unless vehicles and drivers ran in the same run. A step leaves rows an earlier night already loaded alone, so after BE-DP-26 and BE-DP-32 their counts in block 2 should read 0. If you reset since, they read their full counts. The drivers step now also makes the old-data driversinactive(R-DRV-55), so run BE-DP-32 again if its last run was before that change.
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-36.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-36Post 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-36-counts.txt replaces be-dp-36.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-36, local, on the v1 copy, with rentals') as run;select migration.snapshot() as tables_copied;select to_regclass('legacy.v_rental_fee_audit') as rate_history;select domain, field, v1_value, rows from migration.unmapped_values() order by 1, 2, 3;SQLThe last query lists any value no value_map row covers. It should print nothing. migration.run(...) refuses every step while it isn't empty. If it lists 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 line on #302 (a field and a v1 value, never a person).
2 · The four steps
Section titled “2 · The four 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 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' = 'rentals' 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 reason: onboarding rows, v1 driver ids with a bad rate history, and contracts.select v1_table, reason, count(*) as rows from migration.unmatchedwhere run_id = (select max(id) from migration.runs) and step = 'rentals' group by 1, 2 order by 1, 3 desc;-- The unmatched onboarding rows by v1 status.select trim(o.data ->> 'status') as v1_status, count(*) as unmatched_rowsfrom migration.unmatched u join legacy.onboarding o on u.v1_table = 'onboarding' and u.v1_key = o.id::textwhere u.run_id = (select max(id) from migration.runs) and u.step = 'rentals' group by 1 order by 1;-- Rentals by status. A chain's earlier rows are the 'ended' rows (key "<onboarding id>:<n>").select r.status, (m.v1_key ~ ':') as earlier_row_of_a_chain, count(*) as rentalsfrom public.rentals r join migration.id_map m on m.entity = 'rental' and m.v2_id = r.idgroup by 1, 2 order by 1, 2;-- Chains: drivers with an earlier row, and how many rows they hold.select count(distinct r.driver_id) as chained_drivers, count(*) as earlier_rowsfrom public.rentals r join migration.id_map m on m.entity = 'rental' and m.v2_id = r.id and m.v1_key ~ ':';-- Contracts, by status.select status, count(*) as contracts from public.contracts group by 1 order by 1;-- R-RNT-61: contracts that load with no term, because v1's validity is empty or out of range.select count(*) as contracts_with_no_term from public.contracts where term_months is null;-- R-REP-10: no v1 status maps to repossessing, so no repo request opens.select count(*) as repo_requests from public.repo_requests;-- R-RNT-69, R-RNT-70 (D84): the rows that keep v1's audit of a change, and the contracts that keep v1's last edit.select count(*) filter (where r.legacy_data is not null) as rows_with_v1_audit, count(*) filter (where r.legacy_data is not null and r.previous_rental_id is null) as first_rows_with_v1_auditfrom public.rentals r join migration.id_map m on m.entity = 'rental' and m.v2_id = r.id;select count(legacy_updated_at) as contracts_with_v1_edit, count(*) as contracts from public.contracts;SQLA contract with no usable validity in v1 loads with no term (term_months empty), and the reconcile lists it as "no term in v1" until zuki gives the term (R-RNT-61). The step no longer invents 6 months.
4 · 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 'rentals%' and check_name not in ('rentals rate history', 'rentals company cost', 'rentals ignored on purpose')" > ../opleet-private/reconcile-be-dp-36.txtwc -l ../opleet-private/reconcile-be-dp-36.txtThe file holds ids; it stays on your Mac.
5 · What you sign, and the prints
Section titled “5 · What you sign, and the prints”The unclaimed columns are what a signature names (R-MIG-10): the columns of v1's v_rental_fee_audit, contracts and onboarding that no step reads. Since D84 the step reads every one of them but the two nama columns, the driver's name, which you sign as ignored (R-RNT-73). The rate history prints one line for each kind ignored on purpose and a total (R-RNT-72), and the company cost one line (R-RNT-53), until you sign them (R-MIG-06).
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 ~ '^column (v_rental_fee_audit|contracts|onboarding)\.' order by 1;select check_name, row_key, detail from migration.reconcile()where check_name in ('rentals rate history', 'rentals company cost', 'rentals ignored on purpose') order by 1;SQL6 · Only if you want the files attached: the photo copy, in this run
Section titled “6 · Only if you want the files attached: the photo copy, in this run”The driver folder's signed contracts attach only to a contract loaded in this run (R-STO-23), so this block runs BE-DP-23's blocks 2 to 5, in this same run, now that rentals is in its step_log. Do not run BE-DP-23's block 1 (it would begin another run and take another snapshot) or its block 6 (block 7 ends the run). Skip this block if you don't need the files tonight: nothing after it depends on it. It needs about an hour and 10 GB free, and BE-DP-23's inputs.
7 · The end of the run
Section titled “7 · The end of the run”docker exec -i supabase_db_opleet psql -qX -U postgres -d postgres -v ON_ERROR_STOP=1 <<'SQL'select * from migration.photo_counts(); -- after block 6 only; it prints nothing useful before itselect check_name, count(*) as lines from migration.reconcile() group by 1 order by 1;select migration.finish_run('succeeded');SQLExpect
Section titled “Expect”-
Block 1: a run id,
tables_copied35 or so,rate_historylegacy.v_rental_fee_audit(if it is empty, stop: the view isn't exported orv1_liveisn't relinked, see Before), then no unmapped line. -
Block 2:
master_rowsandvehicle_rows0 if BE-DP-26 ran since the reset;driver_rows0 if BE-DP-32 did. Thenrental_rowsis the rentals plus the contracts loaded (plus the template, 1 the first night). The audit lines arerentals,contract_templates(the first night) andcontracts. -
Block 3 (counts from the first run, BE confirms):
-
v1's audit and edits (D84):
rows_with_v1_auditequals theearlier_rowsof the chains (each row after a chain's first begins at a change), andfirst_rows_with_v1_auditis 0 (R-RNT-69).contracts_with_v1_editis the contracts whose v1 row has anupdated_at, every one on a copy where v1 sets it (R-RNT-70). -
Unmatched lines of the table:
onboarding·its driver isn't loaded (the drivers step lists him)andits lead is missing or deleted in v1: about 3 together, fewer or more where the drivers step left leads out;v_rental_fee_auditlines, when a driver's rate history has a gap or dates that don't fit (R-RNT-42, R-RNT-59);contractslines: a contract whose html prints no number or more than one (R-RNT-45).
Post every line with its count. A reason not listed here is new: post it.
-
Rentals by status (R-RNT-52):
- Approve 758 is
pendingabout 425,cancelled297 (D82: every Approve row of a driver on leave or suspended), the 33 old-data rows ignored on purpose (no rental, R-RNT-64), and the unmatched ones, which add up to 758. - Booked 20
booked, less any unmatched. - Listed 1,529 is
active1,526 andpaused2, less the row 2155, ignored on purpose (R-RNT-66), and any unmatched. - No rental for the 133 On Process rows.
- The
endedrows are the earlier rows of the chains, counted apart.
- Approve 758 is
-
Chains (R-RNT-41):
chained_driversandearlier_rowsare not 0. BE-DP-34 counts 97 drivers with two or more audit rows and 117 Listed drivers with a fee change; the printed numbers are the step's, post them. -
Contracts:
signedfor pending and booked rentals,activefor active and paused,terminatedfor cancelled (R-RNT-55). At most 291 (v1's contracts table), less the unmatched contracts and the rentals not loaded. -
contracts_with_no_term: a small number; 6 on the first run, BE confirms. -
repo_requests: 0. No v1 status maps torepossessing, so none opens (R-REP-10).
-
-
Block 4: one line per check. The reconcile of this night is not clean, on purpose:
unmapped values: absent;unmatched rows: one line per unmatched row of every step, so it holds block 3's unmatched rows and the other steps';rentals per status(R-RNT-52): absent. The check subtracts the unmatched and ignored rows, so a line means a row went missing: stop and post it;rentals car by car(R-RNT-51) andrentals and stage(R-RNT-49): absent. A line names a row; post its check and count, keep the ids;rentals cancelled(R-RNT-33): 297 lines until you sign them;rentals no term(R-RNT-61): one line per contract with no term, 6 until zuki gives each its term in a row ofmigration.contract_terms(R-RNT-67); a contract given one is no longer listed;rentals terms unused(R-RNT-67): absent while the table is empty; a line is a row the step did not use ("term given where v1 has one", "term given for no contract"): post it;repo requests(R-REP-12): absent while no rental maps torepossessing;rentals ignored on purpose(R-RNT-64, R-RNT-66): absent. Both lines are signed,Approveby zuki on 2026-10-29 andListed(2155) on 2026-11-05; block 5 prints the check itself;rentals rate history(R-RNT-72): 6 lines, the five kinds and the total; a seventh line,difference, means the kinds and the rows used don't add up to the view's rows: stop and post it.rentals company cost: one line (block 5);v1 unclaimed: the tables and columns no step reads, yours to sign (block 5); of the rentals step's tables only 2 columns, the twonama(R-RNT-73), where there were 7 before D84;- lines of other steps' checks belong to those steps (BE-DP-26, BE-DP-32).
Every line you didn't expect is unexplained: post it and do not sign it.
-
Block 5:
-
Unclaimed: 2 lines,
column contracts.namaandcolumn v_rental_fee_audit.nama(R-RNT-73), each with "no step reads it; rentals reads the table". No value. A third line is a column v1 added since: post it. -
rentals rate history(R-RNT-72): each row ofv_rental_fee_auditcounted once, in the first kind that fits, counts only:1 activity_log: about 35 (35 on the copy of 2026-11-02);2 not an active chain: the rows of drivers whose rental is pending, booked, paused, cancelled, unmatched or ignored;3 before the handover: "N changes of M drivers", about 31 of 24 on the copy of 2026-11-02, plus any change of plate alone dated before a handover;4 plate only: the changes of the plate alone (253 of 877 on the copy of 2026-10-29, before the order takes its share);5 same-day merge: the earlier changes of a day, and every change of a day that nets to no change;total: "U rows used, kept in legacy_data; I ignored on purpose; T in all", where U is block 3'srows_with_v1_auditand T the view's rows.
No
differenceline. The counts move with v1; post them, they are the step's. -
rentals company cost:company_daily_cost, "no source in v1: N rentals loaded with 0", where N is every loaded rental, the earlier rows of chains included. -
rentals ignored on purpose:Approve, "33 ignored on purpose: old data with no rental fee name, no rental (R-RNT-64)", andListed, "1 ignored on purpose: the Listed row with an empty deduction_stopped flag, not in a rental in v1, no rental (R-RNT-66)".
-
-
Block 6: BE-DP-23's expects for blocks 2 to 5, with the driver folder's
kontrakfiles attached to the contracts block 2 loaded (the folder stops waiting for the rentals step). -
Block 7: photo counts if block 6 ran, the reconcile by check again, then
succeeded.
Post blocks 1 to 5, as printed, on #302. Don't post block 4's file. Then say, for each line of block 5 and each check of block 4 that needs your signature (rentals cancelled, rentals no term, the prints, the unclaimed columns), which one it is: you sign these in accepted_differences (R-MIG-06), reviewed in a pull request. Row 2155's Listed line is signed (2026-11-05, R-RNT-66), and the term of the 6 contracts is yours to give in migration.contract_terms (R-RNT-67).
The repo check (R-REP-12). The third check of #302, "every repossessing rental has exactly one open repo request", is registered as repo requests in migration.checks. It prints nothing while no rental maps to repossessing, which is the case on the copy of 2026-10-29, so block 4 shows no line for it; a line would name a v1 onboarding id. Block 3 still prints the repo_requests count (expect 0).
If it fails
Section titled “If it fails”- Block 1,
tables_copied0:v1_liveisn't linked. Run BE-DP-07, then block 1 again. - Block 1,
rate_historyempty:export.sqldidn't export the view, orv1_livewas linked before it did. See Before. - Block 1, an unmapped line: the value has no
value_maprow. Post the line. - Block 2,
migration.step_rentals_no_rate_history: the snapshot has nov_rental_fee_audit. Run BE-DP-06's block 5 and BE-DP-07, then start a new run at block 1. - Block 2,
migration.step_rentals: run the vehicles and drivers steps first: one of them didn't run in this run. Runmigration.run('vehicles')andmigration.run('drivers')in this run, then rentals. - Block 2,
migration.target_org: no organization loaded: master_data didn't run in this run. Run it first. - Block 2,
migration.step_rentals: the snapshot needs leads and deleted_leads: the copy is not the one BE-DP-20 read. Post the line on #302. - Block 2, a constraint name (for example
rentals_…orcontracts_…): post the line on #302. It names the constraint, and the Backend Engineer fixes the step. - Anything else: post the
ERRORline on #302.
pnpm supabase db reset removes everything the night loaded, and BE-DP-07 links v1_live again. If you ran block 6, its files stay in the local v1-hold bucket until the reset. Nothing here touches any remote environment or the v1 copy.
Log each run as a comment on #302: date · who · result, with blocks 1 to 5.
Run of 2026-11-02 (zuki, the copy of that day: 45 tables, 31 real and 14 manual backups; counts and ids only)
Section titled “Run of 2026-11-02 (zuki, the copy of that day: 45 tables, 31 real and 14 manual backups; counts and ids only)”- Rentals 2,552: pending 91, booked 2, active 1,505, paused 5, cancelled 836, ended 113 (113 earlier rows of 112 chained drivers). Contracts 317: signed 11, active 212, terminated 94.
contracts_with_no_term0 (the six terms of #410 are used).repo requests0. - Rentals unmatched 11: 5 driver not loaded, 5 lead missing or deleted in v1, 1 held (#369). Rate-history unmatched 0: drivers 731 and 758 had two changes at an identical timestamp, fixed by #411 (#404). 2605 loads since v1 changed.
- Rate history 1,110 rows used and 35 from
activity_logignored on purpose, 1,145 in all; 24 drivers with 31 changes before the handover not carried. - Unmatched overall 46: drivers 35 (21
bc, 8 leads deleted in v1, 5 no phone, 1 NIK equal to an earlier lead's, #397) and rentals 11.driver NIKs0 (20 before; all fixed in v1). - master pricing 2, both by design; vehicle brands 0 (#316). v1 unclaimed 60.
- Chain figure (R-RNT-41): 112 chained drivers on this copy, 98 on the copy of 2026-10-29; it grows with v1.
The ledger (reconcile ledger) carries these counts against its items.