Skip to content

Data phase · Migration steps

Owner: @zuki · Written by the Backend Engineer · Last reviewed: 2026-11-16 · Conforms to the decisions through D97

  • D3 · Business rules live in Postgres: the rental chain is a trigger on pricing_groups, not app code.
  • #247 · From 2026-10-30, hosted Supabase stops granting new public tables to anon, authenticated and service_role, and every rebuild makes every table anew (D11). So nothing relies on a default grant: the first migration revokes them, and tools/db/gen_rls.py grants each table and view beside its policies (R-ACC-72, pack G3).
  • D10 and D30 · Every refusal raises a key of public.error_key; pack G2 adds no refusal, only constraints that keep Postgres's own codes.
  • D11 · Migration files are edited in place until cutover, so pack G2 changes the M0 files rather than adding new ones.
  • D15 · v1's copy is personal data: steps report counts and ids, never names, phones, plates or VINs. The dump lives in ../opleet-private, outside the repository, and is deleted when the data phase no longer needs it (BE-DP-08's Undo).
  • D17 · The data phase reads a local copy of v1 first (row 1), so the money study and the machinery work on v1's real shape before any domain step.
  • D19 and D27 · Every rule a pack builds gets a pgTAP test whose description starts with its ID, in the same pull request.
  • D22 and D33 · The pull request carries packages/db-types and the reference pages, regenerated with pnpm db:types and pnpm docs:reference, never edited by hand.
  • D28 · From the data phase on, each pack is the Backend Engineer's pull request; zuki runs its steps and merges it.
  • D36 and D65 · v1 is read only through v2_reader, the read-only login of TL-DP-01; no step holds a credential that writes to v1. The copy is a throwaway container on the local stack's network, never on staging.
  • D38 · A rate change starts a new rental row the next day, pointing to the one before; contracts.daily_rate is dropped (pack G2).
  • D43 · driver_stage gains available and inactive, and max_queue_miss is a pool setting, default 3 (pack G2). The rules that move drivers between stages are M3's and M5's.
  • D47 · A VIN is unique within the organization, when there is one (pack G2). v1's duplicates are listed first (BE-DP-01).
  • D51 · The local stack sets Auth's minimum length, the lowercase, uppercase and digit requirement and the 24-hour time-box; the E2E logins' password follows them (pack G2).
  • D53 · Insurance claims are numbered per legal entity like the other documents (R-NUM-10's check). R-NUM-03 is retired and its check removed (#231).
  • D55 · queue_tickets has v1's form fields: the emergency contact, education and birth date (pack G2).
  • D56 · vehicles.contract_status and its enum are supply_status (pack G2).
  • D57 · charge_types.default_due_days, default 3 (pack G2). The due date on charges and changing it are M6's.
  • D50 · v1's logins and their hashes aren't in the copy: the access step reads them live through v2_export (TL-DP-02). The copy is v1's public schema only.
  • D72 · v2 suggests a bulk payment's split oldest due first, and finance decides; migrated payments keep the split v1 recorded, so the money study and the money step build allocations from v1's instalments, never from the suggestion.
  • D70 · A v1 file whose owner is certain but which no v2 record can hold is kept in v1_files, on its driver or its car, and read as the record its v1 folder came from (pack T).
  • D60 and D68 · The photo copy reads v1's file links; BE-DP-08 counts them by form first. v1's one bucket, mop-files, is private, so files are read through a read-only login, never by URL.
  • D67 · The rental lifecycle is decided: rental_status gains returning, repossessing and returned in row 0d (#229), and v1's rows with deduction_stopped become paused. BE-DP-08 counts them on the copy for #155.
  • D69 · v1's onboarding rows map by their v1 status first: Approve becomes pending whatever deduction_stopped says, Listed with deduction_stopped becomes paused with a reason from v1, and an empty flag is an unmapped value (pack 0d's mapping, below).
  • D75 and D80 · v1 is not frozen, so the data phase builds the repo work order's tables ahead of M5 (pack 0i), as a team-session slice that needs no run against v1.
  • D71 · A repossession starts as a repo request. Pack 0e adds repo_requests with its statuses and reasons, one unfinished request per rental refused with repo_request.already_open, read with repo:read; nothing else of D71's repo flow. The rentals step opens one request per rental it maps to repossessing, with from_v1, and its reconcile checks them; which v1 rows those are follows zuki's answer on #268 to BE-DP-16's counts.
  • D74 and D34 · The money step loads each confirmed payment once: from the instalment when one records it, else as its own payment; paid bills with no instalment load one payment of dibayar. D57's default due days apply only where v1 has no due date.
  • D15 and D75 · Staging's money baseline is data-phase/night-staging.expect, TL-DP-04's L0 run 1 of 2026-11-10 as zuki accepted it (#569): names and integers only. night.py staging prints its differences after the counts and never fails on them; be-dp-40.expect stays the local night's check.
  • D84 · v1's letter figures follow the same pattern: debt_letter_items.legacy_amount (R-COL-20).
  • D84 · v1's rate-change audit and contract edits are kept as legacy_ columns, not a table (#405): rentals.legacy_data (R-RNT-69) and contracts.legacy_updated_at (R-RNT-70), edited in place (D11). No API role inserts or updates a legacy_ column on any table but drivers.legacy_id (R-RNT-71): tools/db/gen_rls.py reads the columns from the migrations and grants insert and update by column, and app.legacy_columns() lets R-ACC-72's test catch a column added without regenerating. The rate-history rows the chain doesn't carry are counted in five kinds in rentals rate history (R-RNT-72); both nama columns stay unclaimed until zuki signs them (R-RNT-73).
  • D85 · Read on 2026-11-02: it is M1's admin fee and background checks, and changes nothing in the data phase.
  • D18 and D69, through R-MIG-11 (#553) · v1's grants and denies share one value_map field, so a name mapped onto none would drop a deny and show the login what v1 hid. The access step refuses with migration.dropped_deny while such a deny is unsigned; zuki signs each one by login and name under access dropped denies (R-MIG-06). Three are signed today on two logins: a viewer's etle:read and an admin's etle:write and rental:write, each login also denied the v2 code that would open the page (payment:read, payment:write), until #562 (zuki, 2026-11-06, #187).
  • R-MIG-11 and R-ACC-66 (#771) · v1's repo:read and repo:write map onto none until M5 builds their codes. The access step signs no deny itself: each is zuki's signature, per login, and the step stops until then (zuki, 2026-11-25).
  • D69 and D75, through R-ACC-71 and R-ACC-82 (#570) · v1's aktivasi:read maps onto payment:read, as aktivasi:write onto payment:write: a grant gives a grant override of it and a deny a deny override, so neither is a dropped deny (R-MIG-11). Neither implies what v1's payment:read or payment:write imply, as R-ACC-82 keys those on v1's name (zuki, 2026-11-09). An edit in place of 20261006001600 (D11), so no night stops on it as unmapped (R-MIG-02).
  • D60, D65 and D15, through R-STO-24 (#551) · photo-copy.py place copies from migration.photo_plan(), which marks a file already at its D14 path in its bucket as present. place skips that file without reading v1-hold, deciding by its path only, and never overwrites or deletes a file in a bucket. A dropped connection or a 5xx gets three tries, and its detail names only the error's type (HTTP 0/TimeoutError), never a path.
  • D91 and D92 · vehicle_status has maintenance in place of maintenance_internal and maintenance_insurance, and gains unchecked, edited in place (D11). Both Undermaintain labels map to maintenance for the status and the history, and a loaded history row keeps v1's label as text (D84's naming). 0. Return stays returned (row 0j, #579).
  • D93 · Stock Opname's mode goes, stock_opname_scans comes back, and the expected row loses its scan columns and gains the recheck outcome. v1's mode is still read through value_map, so a new one stops the night (R-MIG-02) (row 0k, #586).
  • D94 · inspections gets two check constraints: an outcome only and always on preparation, a work order only on return or preparation. BE-DP-42 counts the loaded rows each would refuse first; a count above 0 goes to zuki (row 0l, #588).
  • D95 · The notification foundation: four tables, app.notify, resolve and acknowledge, RLS by the type's permission at the pool, Realtime and two organization settings. No type is seeded (row 0m, #590).
  • D96 · gate_passes is one row per stay, with in and out purposes, an out request and typed scans; gate_aspect gains team_use; gate:approve becomes four permissions. v1's gate data loads nothing (R-GATE-14) (row 0n, #594).
  • D97 · permissions.delegable, and delegated and ends_at on overrides; every access helper skips an override past its end. v1's overrides load not delegated, with no end (row 0o, #596).
  • D80 and D89 · Rows 0j to 0o are built on the local stack and need no run against v1, staging or production. A local night on the v1 copy (BE-DP-42, the done-checks of #579, #586 and #588) is zuki's at L0, counts only.
  • D90 · A migrated charge takes its company from the platform of its car, its driver's pref_akun or its own payments' accounts, in that order (R-MON-95, R-MON-96). Contracts keep the entity v1 printed.

TODO: the functions, views and error keys this module exposes, with their status. The Frontend Engineer asks for what it needs in an issue labelled role: backend.

Carried from pack G1 (#150):

  • Checkpoint interval: v1's interval in days becomes checkpoint_interval_weeks by rounding up to whole weeks (14 days is 2 weeks, 10 days is 2 weeks) (R-INSP-06).
  • Phones: v1's numbers load as 62 and the number, with no plus, spaces or dashes; people's phones must start 628, and a number that doesn't is mapped or reported, never loaded as it is (R-CONV-07, R-CONV-16).
  • Roles: v1's roles map onto each organization's own copy of the system roles, at each pool by name, not at an empty pool (R-TEN-03, R-ACC-04).

Pack G2 (#162) · what changed for apps/web and for the data phase's steps. Built: zuki logged BE-DP-03 and BE-DP-04 on #162 by 2026-10-21 (BE-DP-02 was skipped).

  • Rental chains (D38): rentals.previous_rental_id points to the row a rental row continues, and a row has at most one next row (rentals_previous_unique). Changing a pricing group's driver_daily_rate (master_data:write, as before) ends each of its active rentals on the pool's date and starts a new active row the next day, with the same driver, car, company daily cost and billing; a booked or pending rental, or a row that hasn't started yet, takes the new rate in place, with no new row (R-RNT-10, R-RNT-22, D67). A pending rental has no car, so it is in the group through its driver's preferred model. Every other status keeps its rate. The row before is ended with no end reason; every other ended row still needs one (R-RNT-07). app.rental_chain_first(id) gives a row's first row, and v_checkpoint_due anchors on it (R-RNT-17). Show a rental's history by following previous_rental_id; the contract stays on the first row.
  • Contracts: contracts.daily_rate is gone; a contract keeps admin_fee as signed (R-RNT-11). The rate is on the rental row.
  • Driver stages (D43): driver_stage adds available (after listed) and inactive (after resigned); the enum labels in apps/web need both (R-DRV-19).
  • Settings: organization_settings.max_queue_skips is now max_queue_miss, not null, default 3, and pool_settings.max_queue_miss overrides it; read it with app.setting(pool, 'max_queue_miss') (R-SET-08).
  • Vehicles: vehicles.supply_status (enum supply_status: active, replacing, inactive) replaces contract_status (D56). vehicles.vin is optional text, unique within the organization when set: a duplicate is refused with 23505 on vehicles_vin_unique (R-VEH-26).
  • Queue tickets (D55): emergency_contact_name, emergency_contact_phone (628…, R-CONV-16), emergency_contact_relationship, education and birth_date, all optional (R-QUE-09). They are personal data and never reach the queue TV (D58).
  • Charge types (D57): charge_types.default_due_days, not negative, default 3 for every organization's charge types (R-MD-16; changed only through a payment:approve function, M6).
  • Mapping v1: a v1 car's VIN loads uppercase with no spaces or dashes, and an empty one or a dash loads as empty; duplicates are listed by BE-DP-01 before the vehicles step decides which car keeps the VIN. v1's queue form fields load onto the new columns as they are, and a stored due date loads onto its charge.

Pack R1 (#184) · what every later data-phase pack reads. Built: zuki logged BE-DP-05 to BE-DP-08 on #184 by 2026-10-21.

  • v1_live: in the local v2 database only, one foreign table per v1 public table, named as in v1, through the server v1 (postgres_fdw) to the v1copy container. Columns keep v1's built-in types; v1's own types (enums, domains, extension types such as citext) arrive as text, and arrays of them as text[]. Not in any migration, so pnpm supabase db reset removes it and BE-DP-07 makes it again. The Data API doesn't expose it, and only postgres may use it.
  • Staging (row 9) will reach v1 itself the same way, through v2_reader. v1's own types matter there too: the row 9 TL step needs the same text view of them, or the import fails, or worse, lands on v2's types of the same name.

Pack 0d (#229) · D67's rental statuses. Built: merged in #266, and zuki logged BE-DP-14 on 2026-10-22.

  • Rental statuses (D67): rental_status is pending, booked, active, paused, returning, repossessing, returned, ended, cancelled, in that order. The enum labels in apps/web need the three new ones. Every status from pending to returned is live: a car has one live rental (rentals_one_live_per_vehicle, R-RNT-20) and so does a driver (rentals_one_live_per_driver, R-RNT-21), both refused with 23505.

  • The return's reason is the rental's existing end_reason, set when it becomes returning or repossessing (R-RNT-24, R-RNT-25). No new column.

  • rentals.pause_reason (text): why a rental was paused, required while it is paused (rentals_pause_reason, 23514, R-RNT-29). It stays when the rental goes on, as the record of the pause.

  • Rate changes leave returning and repossessing rentals at their rate, with no new row (R-RNT-23); booked and pending rentals already took the new rate in place in G2 (R-RNT-22).

  • A return inspection's return_reason is its rental's end_reason: left empty, it is filled from the rental; a different one is refused with inspection.return_reason_mismatch (P0001, R-INSP-14). The detail is {"return_reason": …, "rental_end_reason": …}.

  • Brands and partner garages (#215, riding along): every member reads vehicle_brands and insurer_garages, and master_data:write adds, changes and deletes them, as for the other master data (R-MD-14, R-MD-15). Deleting one still in use is refused with 23503 (R-CONV-11); set it inactive instead.

  • No status-changing functions. Starting a return, a repossession, the recovery and the BASTK are M5's (R-RNT-24 to R-RNT-28, R-RNT-31).

  • Mapping v1 (D69), for the rentals step (row 5): each v1 onboarding row maps by its v1 status first.

    v1 status deduction_stopped v2 status pause_reason
    Approve any pending empty
    Listed set paused v1: deduction_stopped
    Listed empty an unmapped value in the reconcile (D18), never guessed

    BE-DP-08 counted 731 rows with the flag set: 729 in Approve and 2 in Listed, which zuki reviews before cutover. The rest of v1's statuses map in the rentals step's value_map rows.

Pack T (#251) · the tables row 6's photo copy fills. Built: merged in #275, and zuki logged BE-DP-15 on 2026-10-22.

  • insurance_claim_photos: claim_id, kind (enum claim_photo_kind: accident, ktp, sim, other; R-ASR-06), storage_path at <organization_id>/insurance_claim_photos/<row_id>/<file> (R-ASR-07), taken_at and uploaded_by. Read with insurance:read at the claim's car's pool, app.claim_pool(claim_id) (R-ASR-08); added with insurance:write there (R-ASR-09), and its file uploaded the same way. Only its kind changes, with insurance:write and vehicle:write at that pool: admin_fleet, admin and super_admin (R-ASR-12). An app user's update changes nothing else; the trigger kind_only keeps the rest as it was. No one deletes one (R-ASR-10). Audited.
  • photo_kind gains receipt, for a receipt shown at a checkpoint: v1's nota (R-INSP-15).
  • v1_files, D70's files from v1: a driver_id or a vehicle_id, never both; v1_folder (bc, driver, payment or rebate on a driver; vehicle, checkpoint, asuransi or etle on a car, v1_files_owner_by_folder); v1_label, taken_at, content_type (from Storage), size_bytes and storage_path at <organization_id>/v1_files/<row_id>/<file>. No app user adds, changes or deletes one, or uploads its file (R-STO-15); only the migration does, as postgres. Who reads it follows its folder: as the driver for bc and driver (R-STO-16), payment:read at the driver's pool for payment and rebate (R-STO-17), as the car for the other four (R-STO-18). The car's and the driver's pages list them in M2 and M3.
  • For the photo copy (row 6): a claim photo's file goes in the inspections bucket, and a file from v1 in the bucket of the kind of record it came from: screening for bc, documents for driver, payments for payment and rebate, inspections for the car's folders. Storage's read policy covers all four. The file for an owner that can't be told (R-STO-22) and anonymizing (R-STO-19) are row 6's and M3's.

Money step (#306) · what changed for apps/web. Written; zuki's night is BE-DP-40.

  • payments.proof_path is now nullable: a migrated payment may have none (R-MON-56). A payment with no migrated_from still needs one, refused with 23514. A migrated payment may also have no bank account (R-MON-57).
  • payments.migrated_from is empty for every payment recorded in v2, or bills.data.pembayaran, bills.data.dibayar or payments for one the migration loaded. Writing it is refused with payment.migrated_locked (R-MON-55).
  • charges.inspection_id (nullable) links a migrated Klaim Panel charge to its inspection. Writing it is refused with charge.inspection_locked (R-MON-83).
  • New error keys: payment.migrated_locked and charge.inspection_locked, which apps/web/lib/errors/texts.ts needs labels for.
  • debt_letter_items.legacy_amount is written by the migration only (R-COL-20, R-RNT-71) and read by nothing in v2.
  • A charge's balance can be negative after a refund (R-MON-06); v_driver_balance already counts only balances above zero. A driver's credit is the unallocated part of their payments (R-MON-92).

Rows 0j to 0l (#579, #586, #588) · what changed for apps/web. Built on the local stack (team session 584); BE-DP-42 is zuki's local night.

  • Vehicle statuses (D91, D92): vehicle_status has maintenance in place of maintenance_internal and maintenance_insurance, and gains unchecked; the enum labels in apps/web need both (R-VEH-28, R-VEH-31).
  • vehicle_status_history.legacy_from_status and legacy_to_status (text): v1's labels on a loaded history row, written by the migration only and empty on every row v2 writes (D84's naming).
  • Stock Opname (D93): stock_opname_sessions.mode is gone. stock_opname_scans keeps every scan: session_id, code (the unit code read or the plate typed, not blank), typed, vehicle_id (empty when the read finds no car), expected_id (filled by the database from the session and car, never by the caller, R-OPN-17), is_recheck, scanned_by and scanned_at; for an app user the database sets scanned_by to them and scanned_at to now, whatever is sent. Read with opname:read and added with opname:write at the session's pool, and a writer without it is refused with 42501 before any opname.* key, so no key tells another pool's session status; an app user never changes or deletes one (R-OPN-06, R-OPN-09, R-OPN-10, R-OPN-16).
  • stock_opname_expected loses its scan columns and gains recheck_outcome (enum opname_recheck_outcome: found, confirmed_missing) and recheck_note; confirmed_missing needs a note, refused with 23514 (R-OPN-19). An outcome is set only while the session is finished (R-OPN-20).
  • app.opname_counts(session_id) returns expected, matched, missing, extra_known, extra_unknown and typed, from the expected cars and the scans that aren't rechecks; a car counts once however often it is scanned. Security invoker, so it counts what RLS shows the member (R-OPN-08).
  • New error keys (P0001): opname.session_void (a scan in a void session), opname.session_finished (a scan that isn't a recheck in a finished session) and opname.recheck_not_finished (a recheck scan or outcome while the session is open), each with {"session_id": …} in the detail; apps/web/lib/errors/texts.ts needs labels for them (R-OPN-07, R-OPN-18, R-OPN-20).
  • Inspections (D94): a preparation inspection always has an outcome and no other kind has one (inspections_outcome_preparation, R-INSP-23), and only a return or a preparation inspection has a work_order_id (inspections_work_order_kind, R-INSP-24); both are refused with 23514. Built and tested; the lead commits them apart, after BE-DP-42's counts are 0.

Data phase step IDs are BE-DP-01 and on, numbered in the order they are written, one page each; a pack's section says the order they run in. A step is done when zuki has logged a clean run on its pack's issue (D28).

Pack G2 · The schema the data phase maps v1 onto (timeline row 0a)

Section titled “Pack G2 · The schema the data phase maps v1 onto (timeline row 0a)”

Delivers the schema changes the data phase needs before it maps v1 (#162): rental chains (D38), the stages available and inactive and the queue miss limit (D43), VIN unique (D47), supply_status (D56), the queue form's columns (D55), charge types' default due days (D57) and the local auth settings, with an E2E password of at most 15 characters (D51). It arrives as the Backend Engineer's pull request, each rule first, then its pgTAP test, then the migration edited in place (D27, D11), with the generated files regenerated in the same pull request (D33).

Merged in #212 on 2026-10-20. BE-DP-02 was skipped: the merge came first, and CI's database job on the merge commit ran the same proof (the CTO on #162). BE-DP-03 and BE-DP-04 prove main, and staging is rebuilt with BE-M0-33. BE-DP-01 reads only your copy of v1 and lists its duplicate VINs on #162. It doesn't gate the merge: the duplicates it finds are the vehicles step's work. It runs once pack R1's BE-DP-06 has made the copy.

Not in G2: the rental lifecycle (#155, undecided), the behaviour that moves drivers between stages (M3, M5), the queue's miss count and one open ticket per NIK (M3), copying the queue form to the driver (M3, R-QUE-10), the due date on charges (M6, R-MON-46 to R-MON-48), the training guard (retired by D64) and document numbers in D40's format (M4).

Delivers a copy of v1's public schema on zuki's Mac, which local v2 reads through v1_live, and the counts the steps after it wait for (#184). It replaces Part C's C1 to C3 in the database workflow guide: the dump goes through v2_reader, everything runs from Docker's postgres:17 image because the Mac has no psql, the restore proves every table arrived, and v1's own types reach local v2 as text. The scripts are in tools/migration/v1-copy/; the dump and every row stay on the Mac (D15).

Run the steps in order, once. BE-DP-07 runs again after every pnpm supabase db reset. BE-DP-01 (v1's duplicate VINs, for pack G2) runs once BE-DP-06 is done.

Pack G3 · Explicit grants (timeline row 0f)

Section titled “Pack G3 · Explicit grants (timeline row 0f)”

Makes every grant on public's tables and views explicit before hosted Supabase stops granting new tables by default on 2026-10-30 (#247). The first migration revokes postgres' default privileges in public from anon, authenticated and service_role, so the local stack and CI behave as hosted will. tools/db/gen_rls.py then grants each table and view beside its policies, and writes app.expected_table_grants(), which a pgTAP test compares with the catalog in both directions (R-ACC-72). graphql_public leaves [api] schemas; nothing uses it.

It must merge before 2026-10-30, and staging isn't rebuilt after that date until BE-DP-10 is logged. BE-DP-09 proves the branch on your Mac, apps/web and the E2E logins included; BE-DP-10 rebuilds staging and reads its grants.

Merged in #257 on 2026-10-22, before the deadline; zuki logged BE-DP-09 and BE-DP-10 on #247 the same day (authenticated 77 tables, service_role 78). From here, every new public table or view gets its grant written beside its policies, and 20261006001100_rls.sql is regenerated with gen_rls.py, never edited by hand.

Pack R2 · The money study (timeline row 2)

Section titled “Pack R2 · The money study (timeline row 2)”

Reads v1's money on the copy, read only, so what it finds changes the schema before M6's pages depend on it (D17, #185). The balance of record is the instalments inside bills (D34). v1's payments table was not a source when the study ran; D74 makes it one for the confirmed payments no instalment records, and loads v1's paid bills with no instalment as paid.

BE-DP-11 found the shape first (zuki, 2026-10-22, on #185): each bill is one row of bills.data, with its kind (jenis, seven values), total, v1's own dibayar and status, and its instalments in pembayaran[], 31,662 of them in 4,914 bills, each with jumlah, tgl, bukti, rekTujuan, rekPengirim and, four times, voided. Rebates and refunds are keys on the bill; debts and claim letters are tables of their own. Two findings already bear on the schema: 19,002 of the 23,505 bills have no tanggal and no jatuhTempo, which a v2 charge requires (charge_date, due_date), and at most 3,782 instalments name a proof file, which a v2 payment requires (R-MON-22).

The study's queries are BE-DP-18 and BE-DP-19, written against those shapes. Either may run first.

  • BE-DP-18: each driver's balance from the instalments, and where v1's dibayar and status disagree with them; what a v2 charge or payment requires that v1 lacks (a date, a due date, a driver, a proof, a bank account unless cash, a void reason; CTO-MON-2 on #86); and v1's payments table matched against the instalments.
  • BE-DP-19: how one transfer becomes one payment with allocations (D46); rebates and refunds as adjustments; due dates per bill kind (D57); debts and claim letters as debt letters.

What waits for the counts. zuki accepted the migrated_from proposal on #185 (option a, 2026-10-22): R-MON-21 to R-MON-23 hold for every payment recorded in v2, and a payment migrated from v1 is exempt, marked by payments.migrated_from, which only the migration sets. DOC writes the exceptions and the rule from BE-DP-18's section 2, so they cover exactly the fields v1 lacks. The column then goes in its own small schema pack before the money step, or in the money step's pull request; schema pull requests merge one at a time. D72 decided #148, so the study no longer waits for it: migrated payments keep the split v1 recorded.

zuki logged both on 2026-10-23. Their findings are in the money study's report, with an issue for each that changes a rule or needs a decision: #293 (17,129 bills paid in v1 with no instalment, which D34 would make owed), #294 (586 payments no bill records) and DOC's #295 (the migrated_from exceptions, R-MON-22 and R-MON-23 only, and the dates and reasons of migrated charges and adjustments). BE-DP-24 follows up what they left unexplained: where the paid bills' money is, and what v1's debts and claim letters point at. #185 closes when it is logged and its findings have their issues.

zuki answered #293 and #294 on 2026-10-23, and D74 amends D34 to match.

  • Paid bills with no instalment: v1's Lunas bills whose dibayar covers the total each load one migrated payment.
  • v1's payments table is a real record. A confirmed payment that no instalment records loads onto its driver: its bill takes what it still owes, and the rest is credit.
  • A Pending row isn't confirmed by finance yet, so it doesn't load. The reconcile lists it.

BE-DP-27 counts what that needs.

Pack 0d · D67's rental statuses (timeline row 0d)

Section titled “Pack 0d · D67's rental statuses (timeline row 0d)”

Delivers D67's statuses in the schema, with D69's v1 mapping written above for the rentals step (#229): returning, repossessing and returned, live like the statuses before them; a paused rental's reason; and a return inspection that takes its rental's reason. It arrives as the Backend Engineer's pull request, each rule first (DOC's #230), then its pgTAP test, then the migration edited in place (D27, D11), with the generated files regenerated in the same pull request on a real local stack (D33). After the merge, staging is rebuilt with BE-M0-33, after #247's grants are in if it's past 2026-10-30.

It also carries #215's policies for brands and partner garages, which that issue lets ride along with the next BE pull request.

Not in 0d: the functions that move a rental through these statuses (M5), the rent job that bills them (R-MON-49, M6), and the rentals step that loads v1's rows (row 5).

Pack T · The tables the photo copy fills (before row 6)

Section titled “Pack T · The tables the photo copy fills (before row 6)”

Delivers the homes row 6's photo copy needs (#251, #262): insurance_claim_photos (DOC's #258, with zuki's answer on #263 that only admin_fleet's level fixes a kind), receipt in photo_kind, and D70's v1_files (DOC's #260). It arrives as the Backend Engineer's pull request, each rule first, then its pgTAP test, then the migration edited in place (D27, D11), with the generated files regenerated in the same pull request on a real local stack (D33).

Not in T: the photo copy itself and the place for files whose owner can't be told (R-STO-13, R-STO-14's writes, R-STO-20 to R-STO-22, row 6), and anonymizing a driver's files (R-STO-19, with R-DRV-26).

Pack 0e · The repo request (timeline row 0e)

Section titled “Pack 0e · The repo request (timeline row 0e)”

Adds D71's repo request to the schema, before the rentals step that opens one for every v1 rental it maps to repossessing (#268). DOC's rules came first (#274, #276), then the pgTAP tests in 48_repo_requests.test.sql, then the migration files edited in place (D27, D11):

  • repo_requests: the rental, the organization, status, reason, opened_at and closed_at, columns only (D32). closed_at is set exactly when the request is collected or cancelled (R-REP-14).
  • repo_request_status: open and assigned are unfinished, collected and cancelled closed (R-REP-01). repo_request_reason: unpaid (COL-12), missed_checkpoint (VEH-32) and from_v1 (R-REP-03).
  • One unfinished request per rental: a trigger refuses a second, or a reopened one, with repo_request.already_open, and a partial unique index holds when two are opened at once (R-REP-05, D10, D30).
  • Who reads: repo:read at the rental's pool, with the partner filter (R-REP-13, R-ACC-44). No app user adds, changes or deletes a request; M5's functions will (R-REP-02, D3). repo:read joins the catalogue in M5 (R-ACC-66), so until then only the database owner, the migration, reads them. The table is audited (R-AUD-01), and its grant is written beside its policy (R-ACC-72).

BE-DP-17 proves the branch and commits the regenerated types and reference pages; the new key needs its Indonesian and English text from the Frontend Engineer on the same branch (D33). BE-DP-16 found where v1 records a repossession (run 2026-10-22, on #268).

Not in 0e: repo work orders, their units and PICs, repo_leader, repo:assign, and the functions and jobs that open, assign and close requests (M5, #271). The rentals step's part, one open request per repossessing rental and its reconcile, lands with that step (row 5).

Pack 0g · Stock Opname in the schema (timeline row 0g)

Section titled “Pack 0g · Stock Opname in the schema (timeline row 0g)”

Stock Opname is a feature v1 added, rebuilt as v1 has it (D75, #320), so the operations step has a home for v1's rows. In 20261006000700_operations.sql:

  • stock_opname_sessions: a session at one pool, with its mode, an optional assignee, deadline and note, and a status of open, finished or void. A finished or void session has a finish time (R-OPN-01 to R-OPN-03).
  • stock_opname_expected: each car the session expects, once, with its status at the start. A scanned car has its time and member (R-OPN-04 to R-OPN-06).
  • Policies: opname:read and opname:write at the session's pool (R-OPN-09, R-OPN-10). The two codes are in the seed: super_admin, admin, admin_fleet and checker hold both, and viewer holds opname:read (R-ACC-86 to R-ACC-89). The access step maps v1's opname:write onto it.

The functions that start, scan and finish a session, and its counts, are M5's (R-OPN-07, R-OPN-08). The operations step loads v1's rows (R-OPN-11 to R-OPN-13, #304).

Pack 0i · The repo work order in the schema (timeline row 0i)

Section titled “Pack 0i · The repo work order in the schema (timeline row 0i)”

Adds the tables D71 left to M5 and D75 moved into the data phase (#357, a team-session slice by D80). DOC's rules R-REP-15 to R-REP-27 came first, then the pgTAP tests in 57_repo_work_orders.test.sql, then the migration files edited in place (D27, D11):

  • repo_work_orders: the organization, one pool_id, status (active or closed), assigned_by, assigned_at and closed_at, columns only (D32). closed_at is set exactly when the work order is closed and never before assigned_at (R-REP-15 to R-REP-17). There is no deadline column: it is assigned_at plus 24 hours, and zuki hasn't answered whether the Repo Leader may pick another (#269). No column holds the collection rate (R-REP-18).
  • repo_work_order_units: one request in a work order, with status (pending, collected or failed), closed_by and closed_at. A request is a unit of the same work order once, and has at most one pending unit (R-REP-20 to R-REP-22). closed_at is set exactly when the unit isn't pending; closed_by is empty while pending, required when collected, and a PIC or empty when failed (the job at the deadline leaves it empty) (R-REP-23, R-REP-24).
  • repo_work_order_pics: a profile once per work order (R-REP-25). A unit's closed_by must be one of its work order's PICs (a composite foreign key, and the key below).
  • Three keys (D10, D30), raised by a trigger on the unit: repo_work_order_unit.pool_mismatch (the request's rental is at another pool, R-REP-19), repo_work_order_unit.already_pending (R-REP-21, backed by a partial unique index) and repo_work_order_unit.closer_not_pic (R-REP-25). A closing time before the assignment is a check violation, 23514, with no key.
  • Who reads: repo:read at the work order's pool. A member limited to rental companies sees a work order and its PICs when at least one of its units is on one of their rentals, and only those units (R-REP-26, R-ACC-44). No app user adds, changes or deletes any of the three; M5's functions will (R-REP-27, D3). repo:read joins the catalogue in M5 (R-ACC-66), so until then only the database owner reads them. Nothing migrates into them.
  • Not audited: the audit log watches the tables R-AUD-01 lists, and these aren't among them; adding them is a rule change for DOC. (work_order_id would also make app.audit_row look for the pool in the maintenance work_orders.)

The three new keys need their Indonesian and English text from the Frontend Engineer on the pull request's branch (D33).

Not in 0i: the functions that assign and close a work order and close a unit, the 24-hour job and the daily checkpoint job, repo_leader, repo:assign and the views (M5, #271).

Pack R4 · The migration machinery (timeline row 4)

Section titled “Pack R4 · The migration machinery (timeline row 4)”

The frame every night runs in, inside the v2 database (D17, D18, D52, #186). supabase/migrations/20261006001400_migration.sql makes the migration schema, which only the database owner can use (R-MIG-08):

  • begin_run() and finish_run(): one id per night.
  • snapshot(): v1_live becomes legacy, in one transaction, counted (R-MIG-01).
  • value_fields, value_map and unmapped_values(): no default mapping, so no step starts while a value is unmapped (R-MIG-02).
  • v2_id(entity, key): the same uuid for a v1 key on every run, recorded in id_map (R-MIG-03).
  • unmatched_row(): a row a step can't place is listed, never dropped (R-MIG-04).
  • run(step): runs migration.step_<step>() with the audit triggers off for its load only, then writes one migrated entry per table (R-AUD-15, R-AUD-16).
  • checks, accepted_differences and reconcile(): every differing row not signed (R-MIG-05, R-MIG-06). Signatures are rows in the migration file, so every rebuild keeps them; the first is zuki's, for v1 having no photos before 2026-08-24 (#184).
  • file_map: one row per v1 file, for the photo copy (D70, R-MIG-07).

Each domain step (row 5) adds its migration.step_<name>(), its value fields and its checks. BE-DP-12 proves the branch and commits the regenerated types; BE-DP-13 runs a first night's frame on the v1 copy.

Merged in #265 on 2026-10-22. zuki logged BE-DP-12 (no file changes) and BE-DP-13 on #186 the same day: run 2 succeeded, with 34 tables and 164,076 rows in the snapshot, 0 unmapped values and 0 unexplained rows.

v1 tables and columns no step claims (#324, R-MIG-10, D75): each step's migration file claims, in migration.claims, the v1 tables and columns its code reads. The reconcile's check v1 unclaimed then lists, each night, every table of the snapshot that no step reads (with its row count) and every unread column of a table that some step reads. A line is claimed by a step or signed as ignored (R-MIG-06). It stops nothing.

Row 5 · The domain steps, first v1's shapes

Section titled “Row 5 · The domain steps, first v1's shapes”

Each domain step loads one part of v1 into v2 with migration.step_<name>(), its value fields and its reconcile checks, in this order: master_data (#279), access (#278), which needs master_data's organization, pools and rental companies, vehicles (#280), drivers (#281), then rentals (after #268), operations and money (after row 2). Each is the Backend Engineer's pull request with pgTAP tests (D19), and the photo copy (row 6, #262) attaches its files to the rows they load.

No step can be written before v1's tables are known. BE-DP-08 counted them and BE-DP-11 printed the money tables' shapes; BE-DP-20 prints the rest, posted on each step's issue, so each step maps v1's real columns and values. The access step reads v1's logins live through v2_export (TL-DP-02) and needs no shapes from the copy.

What the shapes don't settle goes to the step's issue before its pull request. One is open now: which v1 drivers had a repossession. BE-DP-16 ran on 2026-10-22 (#268): no status in v1 reads like one, and v_driver_profile.denda_repo is filled on 333 rows (313 Approve, 17 Listed, 3 with no onboarding status). Whether that marks a repossession in progress or a finished one is for the CTO and zuki to read on #268, under the mapping zuki accepted there; the rentals step's R-REP-10 and the drivers step's R-DRV-37 follow the answer.

zuki logged BE-DP-20 and BE-DP-21 on 2026-10-23. The first two loads are written from them, in supabase/migrations/20261006001500_migration_master_vehicles.sql, with 24 tests in 50_migration_master_vehicles.test.sql (#279, #280):

  • What v1 doesn't hold: migration.target, target_pools and target_legal_entities hold the organization the load goes into, its pools and its legal entities. Their rows come from zuki's answers to BE-DP-25 (#280, 2026-10-26) and ship in the migration.

  • step_master_data():

    • the organization, its pools and its legal entities;
    • v1's lists in app_settings: brands, types as models, rentalFees as pricing groups (with admFees as their admin fee), partners as rental companies, asuransi as insurers, and the garages;
    • one row per name, case aside (R-MD-18), and a charge type for each bill kind no system one means: Lain-lain becomes other (R-MD-17).
    • an insurer for each name v1's claims hold that asuransi lacks, case aside, spelled as most claims spell it (R-MD-21). A tie between two spellings is an unmapped value, asuransi_claims.data->asuransi:spelling with the name in lower case, until a value_map row names the spelling; a claim name with a value_map row in asuransi_claims.data->asuransi adds none (R-ASR-15). Tests in 60_migration_claim_insurers.test.sql.
  • step_vehicles():

    • one car per vehicle_master row, keyed by its unit_id (R-VEH-28), with its status from vehicle_status, which v1 keeps current, else from vehicle_master (#324);
    • its type, partner and service area through value_map onto one model, rental company and pool;
    • its status and status_mobil onto status and supply_status;
    • a row it can't place is unmatched, with its reason, and a plate clash is never renamed (R-VEH-29);
    • every plate a car carried, and its temporary plates, onto the car as vehicle_plate in id_map, which the photo copy reads (R-VEH-30).
  • The checks: vehicles loaded, vehicle plates, vehicle VINs, vehicle brands, master names, master pricing and master insurers added (R-MD-21: each insurer the claims alone named, with its claim count).

  • What's mapped already:

    • v1's seven bill kinds and its car statuses;
    • BE's two choices for zuki to confirm in BE-DP-25: Not Aktif retires a car, and an empty status_mobil is active.

    A car's type, partner and service area, and each type's powertrain, wait for BE-DP-25's lists. Until their rows are in, unmapped_values() lists them and the night stops before the steps (R-MIG-02).

  • BE-DP-25 · The values the master data and vehicles steps map, and what v1 doesn't hold

  • BE-DP-26 · A night on the v1 copy with master data and vehicles, after the pull request with BE-DP-25's answers

The access step (#278, D50) is in supabase/migrations/20261006001600_migration_access.sql, with 26 tests in 51_migration_access.test.sql, written from BE-DP-21's block 2 (64 logins, every hash $2a$10$):

  • v1's logins come in each night through v2_reader, not the snapshot, which holds v1's public schema only. tools/migration/v1-copy/logins-export.sql reads v2_export.auth_users and auth_identities (TL-DP-02) into ../opleet-private, and the night loads them into migration.v1_auth_users and migration.v1_auth_identities, owner-only like the rest of the schema (R-MIG-08), and empties them at its end. The step stops on a night with none loaded, rather than move none.

  • step_access():

    • one login per v1 login, with its id, its email in lower case and its password hash (R-ACC-58), its email identity, and its v1 name as the profile's name. Auth's token columns are empty, never null, so sign-in reads them. v1's app metadata stays behind: v2 reads access from its tables;
    • the photo reader is left out by its v1 id, in migration.logins_left_out (R-ACC-73);
    • one membership in the organization, with the v1 role's system role at every pool, since v1 had no pools (R-ACC-75);
    • allowed_perms as grants and allowed_perms_denied as denies, renamed through R-ACC-71's table, at every pool; car:delete gives nothing (D39). A deny whose name maps onto none stops the step until it is signed (R-MIG-11): select * from migration.dropped_denies() lists each by login id and name;
    • allowed_partners as the member's rental companies (R-ACC-76);
    • a login it can't place is unmatched, with its reason (R-MIG-04): deleted, banned, anonymous or SSO in v1; no email, password or role; a role with no system role; a partner with no rental company, since moving it without one would show every partner's cars (R-ACC-42); an email another v2 login has.
  • It ends no session (R-ACC-74): app.end_sessions_on_access_change() skips rows written while migration.loading is on and the caller isn't an API role. An access change made in the app still ends the member's sessions.

  • The values it maps, read from tonight's loaded logins only, so a night without them (BE-DP-26's) isn't stopped: v1's role names and partners, which wait for zuki's values, and permission names, whose rows are R-ACC-71's table. A name outside the table stays unmapped.

  • The checks: access logins (every v1 login moved, left out or unmatched, with its identity), access hashes (compared in the database, never printed), access menus (per member and pool, the permissions v2 gives are v1's, R-APP-05) access modules (every page in a login's v1 allowed_modules opens in v2 at every pool, R-ACC-81) and access dropped denies (each v1 deny that maps onto no v2 code, by login id and name, R-MIG-11).

  • BE-DP-28 · Before the merge: the access step's tests, then the generated files

  • BE-DP-29 · A night on the v1 copy with the access step, and one sign-in with a v1 password, after the access step's pull request and BE-DP-25's rows

The drivers step (#281, D66, D73) maps v1's lead, onboarding, bc and queue statuses and its lead sources through value_map. unmapped_values() reads every field on every night, so its rows ship complete with the step, from BE-DP-30's lists.

The rentals step (#302, D67, D69) loads v1's onboarding rows as rentals with their contracts. Its values and v1's shapes are listed first, for DOC's rules and its value_map rows.

What the rentals step does (R-RNT-32 to R-RNT-53, 20261006001800_migration_rentals.sql, tests in 55_migration_rentals.test.sql):

  • Runs after vehicles and drivers, and refuses to run before them. One rental for each onboarding row, keyed by its onboarding id in id_map (entity rental); a rental chained from the rate history keeps that key on its live row, and its earlier rows are <onboarding id>:<n>.
  • Values it maps (domain rentals): the status (Approve pending, Booked booked, Listed by its flag, On Process none), a Listed row's deduction_stopped (false active, true paused), deduction_frequency (Daily) and the 21 tariffs of rentalFees. An empty flag, fee name or frequency has no row, so the run stops until zuki maps it (R-RNT-36, R-RNT-38, R-RNT-39). The fee name and the frequency are read on loaded rows only.
  • The chain is built from v_rental_fee_audit, bills_archive rows where the fee changed, in the pool's date; activity_log rows are not used (R-RNT-43). A driver whose chain has a gap, ends at another fee than his row today, or has dates that don't fit is unmatched by v1 driver id (v_rental_fee_audit) and none of his rows loads (R-RNT-42).
  • Contracts: the number is the text after No. in contracts.html, in the shape AAA/AAA/9999/9999, exactly once; the contract is on the live row. contracts.template_id is not null, so the step writes one inactive placeholder template ("Kontrak dari v1") under the first legal entity; no rule names a template, and the contract's status (active for an active or paused rental, signed for pending and booked, terminated for cancelled) and its start (kontrak, else the contract's saved date) are the step's, for the CTO to read.
  • Its checks (all listed in the reconcile): rentals per status (R-RNT-52), rentals car by car (R-RNT-51), rentals and stage (R-RNT-49), rentals cancelled (R-RNT-33), rentals rate history (R-RNT-43) and rentals company cost (R-RNT-53). The last two are prints, not differences: they list one row each night until zuki signs them (R-MIG-06).
  • Not built: R-REP-10 opens no repo request, because no v1 status maps to repossessing; the test asserts none opens.

The operations step (#304, D70, D75) loads v1's checkpoints, insurance claims, ETLE rows and Stock Opname's session; v1's gate logs are test data and load nothing (R-GATE-14). Its values and v1's shapes are listed first, for DOC's rules (#356), its value_map rows, and the proposal on work orders, maintenance and preparation.

What the operations step does (R-INSP-16 to R-INSP-22, R-WO-10 to R-WO-15, R-GATE-14, R-ASR-13 to R-ASR-15, R-ETLE-06 to R-ETLE-08, R-OPN-11 to R-OPN-14, R-VEH-31; 20261006001900_migration_operations.sql, tests in 58_migration_operations.test.sql):

  • Runs after master_data, vehicles, drivers and rentals, and refuses to run before them. A car is found by its unit, else by a plate it carried; a plate two of v1's cars carried finds neither.
  • Keys (id_map): inspection (checkpoints id, which the photo copy reads), preparation_inspection, work_order, work_order_event, maintenance, insurance_claim, insurer_garage, etle_violation, opname_session, opname_expected, vehicle_status and inspection_item_type.
  • The schema it needs, edited in place (D11):
    • work_orders.reason is empty on a row from v1, which keeps v1's text in legacy_reason, and a check keeps one of the two (R-WO-14).
    • inspections.work_order_id holds a preparation inspection's work order (D47, R-INSP-21).
    • v1's who-did-it text goes into legacy_ columns (D84): legacy_in_by, legacy_in_role, legacy_in_note, legacy_out_by and legacy_out_role on gate_passes, which nothing from v1 fills now (R-GATE-14); legacy_by on work_order_events; legacy_by, legacy_driver and legacy_driver_id on vehicle_status_history.
    • app.inspection_return_reason() skips a row the migration loads, so a return keeps v1's reason (R-INSP-18).
  • The item types for v1's 26 checklist items and 7 pieces of equipment are made by the step, from migration.inspection_items (R-INSP-19).
  • Values it maps (domain operations): every field the rules name. Some fields ship with no row, because their values aren't in the posted reads: the history actions, ETLE's violation types, the claims' accident types, the one unmapped return reason, and insurer and garage spellings. BE-DP-38's first night lists them.
  • v1's gate logs and exit tickets load nothing and are signed as ignored (R-GATE-14): the gate wasn't in use (zuki on #304, 2026-11-03).
  • Its checks are the 16 named operations …. The prints (rentals found, not checked, no work order, the ETLE payer and unknown driver) list until zuki signs them.
  • Not built: R-INSP-20's damage rows. v1's nota counts its damaged panels (jumlah_panel, panelBaret) and keeps their photos, but names no panel, so no inspection_damages row can be placed. The step bills nothing, and the test proves that part.

Pack R6 · The photo copy (timeline row 6)

Section titled “Pack R6 · The photo copy (timeline row 6)”

Copies v1's files into v2 (#262, D14, D60, D68, D70), as approved on #184 and directed by the CTO on #262 (2026-10-22): copy every file's bytes now, attach only to records already loaded, count the rest as waiting for their step, and run after row 5's steps in a night.

  • The bytes, every night, first: tools/migration/photo-copy.py mirror reads each object of mop-files as the photo reader and writes it to the private bucket v1-hold under its object id, a top-up that skips what's held. No policy names v1-hold, so no app user reads it (R-STO-22). File names never reach a v2 path: every path ends in the object id.

  • The manifest: migration.photo_manifest() classifies every object into migration.file_map (R-MIG-07) from tonight's object list (migration.v1_objects, through v2_reader), the copy's results, the legacy snapshot and id_map:

    • waiting when the step that loads its owner or its record hasn't run tonight (R-STO-23);
    • held when its owner can't be told (R-STO-22);
    • attached by the v1 row that names it, then by a one-of-a-kind label, then by the day (R-STO-13);
    • v1_file when its owner is certain and no record fits (R-STO-14);
    • not_copied when v1 wouldn't give its bytes.

    The folders and labels are data: migration.photo_folders (owner, the step that loads it, the records a file can go on) and migration.photo_labels (#184's approved labels, and R-ASR-11's).

  • Placing and recording: photo-copy.py place copies each attached file and file from v1 from v1-hold to its D14 path in its bucket (R-STO-10), and migration.run('photos') writes the rows: inspection, background check and claim photos, a car's STNK, the path columns, and v1_files.

  • The counts: migration.photo_counts() per folder, and the reconcile check files not copied (R-STO-20).

What each domain step must register in id_map for its folders to attach, so the photo copy finds them (R-MIG-03): driver (lead id) and background_check (bc id) from the drivers step; vehicle_plate (every current and former plate, upper case without spaces) from the vehicles step; inspection (checkpoints id), etle_violation and insurance_claim from operations; contract (onboarding id) from rentals; payment_instalment (bill id and instalment index) and charge_adjustment (bill id with :rebate or :refund) from money.

BE-DP-22 proves the branch; BE-DP-23 runs the copy on the local stack. Until row 5's steps merge, every file waits; each step's merge lets the next run attach its folders, so BE-DP-23 is rerun after each.

Not in R6: v1's 56 files kept inline in rows (decoded onto their records once those steps load them, #262), the anonymizing of a driver's files (R-STO-19), and the nightly job that runs it on staging (row 9, #187). R-STO-11 and R-STO-21 stay planned: the first needs the money and operations steps' links, the second their records' dates.

Row 0m (#590) · the notification foundation (D95). Built on the local stack (team session 584); no type is seeded, and marking read, dismissing, preferences, the delivery order, escalation and the clean-up are M7's (R-NTF-20 to R-NTF-24, R-NTF-27).

  • Tables: notification_types (code, module, default_severity, permission_code, escalates, role_live_from: system role code to severity), notifications (organization, pool, type_code, subject_table and subject_id, severity, recipient_membership_id, opened_at, acknowledged_by and _at, resolved_at), notification_receipts (read_at, dismissed_at per membership) and notification_preferences (module or type_code, delivery, min_live_severity). Enums notification_severity (info, action, urgent) and notification_delivery (live, digest, off).
  • Reads: every signed-in user reads the types; a notification is read by its recipient when it names one (R-NTF-14), otherwise by a member holding its type's permission at its pool (R-NTF-13); receipts and preferences by their own membership. No direct writes on any of the four (R-NTF-02, R-NTF-12).
  • app.notify(type_code, subject_table, subject_id, pool_id, recipient_membership_id default null) returns the open notification's id, opening one only when none of that type and subject is open (R-NTF-08); an unknown type is refused with notification.type_not_found. app.resolve_notification(type_code, subject_table, subject_id) resolves the open one, and does nothing when none is (R-NTF-15). Both are for other functions, not the app.
  • acknowledge_notification(notification_id) (RPC) stamps acknowledged_by and _at for the caller. Refusals, in order: notification.not_found (also for one the caller doesn't see, R-NTF-17), notification.already_resolved (R-NTF-19), notification.already_acknowledged (R-NTF-18).
  • Realtime: notifications is in the supabase_realtime publication (R-NTF-25); a client subscribes and RLS filters what it gets.
  • organization_settings: notification_escalation_hours (jsonb, default {}: a key is an escalating type's code, a value whole hours of at least 1; refused with settings.not_escalating_type or settings.escalation_hours_invalid, R-SET-14, R-SET-15) and notification_digest_at (time, default 07:00, R-SET-16), both written under master_data:write.
  • Removing a member removes the notifications sent to them by name, their receipts and their preferences (R-NTF-26).

Row 0n (#594) · the gate pass (D96). Built on the local stack (team session 584); transfers and the gate's RPCs are M5's.

  • gate_passes is one row per stay (R-GATE-15): in_purpose and out_purpose (enum gate_purpose), in_typed and out_typed (R-GATE-32), an out request (out_requested_at, out_requested_by; out_at needs it, R-GATE-33), team_membership_id and team_reason (R-GATE-27); a guest pass holds a plate and no car, and goes out as a guest (R-GATE-28). One open stay per car (gate_passes_vehicle_open_unique, R-GATE-16). kind and the legacy_ columns are gone; v1's gate data loads nothing (R-GATE-14).
  • Stamps: an app user's in, out request and out steps are stamped with auth.uid() and now() (R-GATE-04), and an approval's approved_by and _at likewise (R-GATE-13).
  • Approvals: gate_aspect is checkpoint, service, debt or team_use (R-GATE-19). gate:approve is now four permissions, gate_debt:approve, gate_service:approve, gate_checkpoint:approve and gate_team:approve, each needed to insert an approval of its aspect (R-GATE-20 to R-GATE-23). Finance holds the debt one, admin_fleet the other three, admin and super_admin all four (R-ACC-223). The gate approvals page opens with any of the four (R-APP-15, R-ACC-228).

Row 0o (#596) · delegation's data phase (D97). Built on the local stack (team session 584); delegate_permission() and revoke_delegation() are M1's (R-ACC-234 and on).

  • permissions.delegable (boolean): true for gate_debt:approve, gate_service:approve, gate_checkpoint:approve and gate_team:approve only (R-ACC-229).
  • member_permission_overrides.delegated (boolean, default false) and ends_at (timestamptz, empty for no end). A delegated deny is refused (member_permission_overrides_delegated_grant, 23514, R-ACC-230); a delegated row needs granted_by and a reason that isn't blank (member_permission_overrides_delegated_by, R-ACC-231); ends_at only on a delegated row (member_permission_overrides_ends_at, R-ACC-232). v1's overrides load not delegated, with no end.
  • Past its end a delegation gives nothing (R-ACC-233): every access helper reads overrides through app.live_overrides, so RLS, my_permissions(), the count of user managers and the member-management checks leave it out, with no change to the row and no session ended.
  • Only a delegable permission is delegated, whoever writes the row: a delegated row, inserted or updated, on a code that isn't delegable is refused with access.not_delegable (P0001, with permission_code; R-ACC-229, R-ACC-235's key). So user:write is never delegated or given an end, and the count of user managers (R-ACC-40) rests on no override that ends.
  • pool_members(): each entry of overrides gains delegated and ends_at, and a delegation past its end is still listed; how it is shown is M1's (R-ACC-242).