MIG · Migration
The v1 to v2 migration runs inside the v2 database: every night on staging, and once at cutover (D2, D17). A night begins a run, takes a snapshot of v1 into the legacy schema, checks that every v1 value a step maps has a mapping, runs each domain step, and ends with the reconcile (D18). This page holds the rules of that machinery (data phase row 4, #186). The domain steps (row 5) and the photo copy (row 6) follow them. How the load writes the audit log is under Audit log (R-AUD-15, R-AUD-16, D52). Code MIG.
Not yet a rule
Section titled “Not yet a rule”- What a signature covers (#323): R-MIG-10 says a table or column signed as ignored is no longer listed. It doesn't say whether signing a table also covers the columns v1 adds to it later. Reading R-MIG-06 strictly, a signature covers the rows it names, so the new column would be listed. Asked of the CTO on #323.
- New keys inside v1's jsonb columns (such as the money kept in
bills.data): R-MIG-10 sees tables and columns only. A key v1 adds inside a jsonb column is no new column, so no step is asked to claim it. Asked of the CTO on #323.
R-MIG-01 · A run's snapshot copies every v1 table into legacy from one moment, with each table's row count recorded against the run
Section titled “R-MIG-01 · A run's snapshot copies every v1 table into legacy from one moment, with each table's row count recorded against the run”- Status: built
- Example: given a run just begun and a v1 copy of 34 tables, when the snapshot is taken, then legacy holds all 34 tables as they were at that moment, read in one transaction, and each table's row count is recorded against the run. The steps read legacy, never v1 itself. With no run open, the snapshot, a step and an unmatched row are refused; a step whose name has no step function is refused too.
- Refusal: migration.no_open_run (no run is open); migration.unknown_step (the step named has no function).
- Who: the migration machinery, run by the database owner (R-MIG-08).
- Source: D17, D18; proposed by the Backend Engineer on #186.
R-MIG-02 · No step runs while a v1 value it maps has no row in value_map
Section titled “R-MIG-02 · No step runs while a v1 value it maps has no row in value_map”- Status: built
- Example: given v1 cars whose status Listed has no mapping, when the unmapped values are read, then they list the field, Listed and how many rows hold it, and every step is refused; once Listed is mapped, nothing is listed and the steps run. There is no default mapping, so a value nobody mapped is never guessed. An empty v1 value is mapped like any other.
- Refusal: migration.unmapped_values.
- Who: the migration machinery.
- Source: D18 (zero means zero unexplained differences); D69 (an unmapped value is never guessed); #186.
R-MIG-03 · A v1 key gets the same v2 id on every run
Section titled “R-MIG-03 · A v1 key gets the same v2 id on every run”- Status: built
- Example: given v1 driver 1042, when tonight's run, a rebuilt staging tomorrow and the cutover run each give them a v2 id, then all three give the same one, so on production they keep the id they had on staging. The id comes from the entity and the v1 key alone, so the same key in two entities gives two ids, and each pair handed out is recorded in the id map.
- Refusal: none.
- Who: every domain step.
- Source: D2 and D11 (staging is rebuilt every night, so an id can't be remembered from the night before); #186.
R-MIG-04 · A v1 row a step can't place is listed with its reason, never dropped: in migration.unmatched, or as ignored on purpose, under a rule of its own or D87
Section titled “R-MIG-04 · A v1 row a step can't place is listed with its reason, never dropped: in migration.unmatched, or as ignored on purpose, under a rule of its own or D87”- Status: built
- Example: given a v1 car with no pool, when the vehicles step can't place it, then migration.unmatched lists it against the run, with the step, the v1 table, its key and the reason, and the reconcile shows it (R-MIG-05). Ignored on purpose is the third outcome beside loaded and unmatched, and a last resort: given an odd v1 row dated 2026-08-20 that a v2 rule refuses, and an investigation that finds no other field, history or linked row of v1 that places it, when the step meets it, then it loads nothing, stays in the copy, and the reconcile lists it as ignored on purpose under D87, with its reason and a count. The row's own date must be on or before 2026-09-30: the date the row records for when it happened in v1, such as when it was opened, created or occurred, never when it was last edited and never the copy's date. A faulty row dated later is still a question for zuki, and a correct row of the same date loads as before, if it fits: nothing is cut by date alone. Each step's own rule names its rows and carries the test (D87). A rule of its own can also ignore rows on purpose, outside D87's last resort, as R-GATE-14 and R-RNT-64 do, and that rule says how they are shown.
- Refusal: none.
- Who: every domain step.
- Source: D18; D60 (never a silent skip); D87 (the last resort); #186.
R-MIG-05 · The reconcile lists every row that differs, except those signed in migration.accepted_differences
Section titled “R-MIG-05 · The reconcile lists every row that differs, except those signed in migration.accepted_differences”- Status: built
- Example: given the unmatched car U-3, when the reconcile runs, then it lists U-3 under its check; once zuki signs that row with a reason, it is no longer listed. A clean night lists nothing. Each domain step adds its own checks; the machinery starts with two, unmapped values and unmatched rows.
- Refusal: none.
- Who: the migration machinery, and every check a domain step adds.
- Source: D18; D34 (a money difference counts until it is signed); #186.
R-MIG-06 · An accepted difference names its check, the row or rows it covers, the reason, who signed it and when
Section titled “R-MIG-06 · An accepted difference names its check, the row or rows it covers, the reason, who signed it and when”- Status: built
- Example: given a difference recorded without a reason, when it is saved, then it is refused. The first one signed is zuki's, from #184: v1 kept no photos before 2026-08-24, so older records aren't counted as missing their files. Signed differences are written in the migration file, so every nightly rebuild keeps them and each signature is reviewed in a pull request.
- Refusal: none: not_null_violation (23502).
- Who: whoever signs the difference; each signature is reviewed in the pull request that writes it.
- Source: D18; #184, #186.
R-MIG-07 · Every v1 file has one row in migration.file_map: attached to a record, kept as a file from v1, held as unmatched, waiting for its step, or not copied, with its reason when it isn't attached
Section titled “R-MIG-07 · Every v1 file has one row in migration.file_map: attached to a record, kept as a file from v1, held as unmatched, waiting for its step, or not copied, with its reason when it isn't attached”- Status: built
- Example: given a v1 checkpoint selfie, when the photo copy places it, then file_map has one row for it, attached to its inspection photo and saying how it matched: by the v1 row that names it, by a one-of-a-kind label or by the day. A second row for the same file is refused. A file kept as a file from v1 (
v1_file), held because its owner can't be told (held, R-STO-22), waiting for the step that loads its record (waiting, R-STO-23) or not copied (not_copied) has a reason, and the reconcile counts each per folder (R-STO-20). - Refusal: none: unique_violation (23505) for a second row; check_violation (23514) for a file not attached with no reason.
- Who: the photo copy (data phase row 6), which fills the table.
- Source: D70; D60 (every file moves, and one that can't is never a silent skip); D18; the CTO's approval on #184.
R-MIG-08 · No API role can use the migration or legacy schemas
Section titled “R-MIG-08 · No API role can use the migration or legacy schemas”- Status: built
- Example: given a signed-in user, or a request with the publishable or secret key, when it reads migration.runs or a table in legacy, then Postgres refuses it. Only the database owner reads or runs the migration.
- Refusal: none: insufficient_privilege (42501).
- Who: anon, authenticated and service_role.
- Source: D65 (nobody holds standing write access to a database); D15 (legacy holds v1's personal data); #186.
R-MIG-09 · Ending a run, whatever its status, empties the v1 logins it loaded
Section titled “R-MIG-09 · Ending a run, whatever its status, empties the v1 logins it loaded”- Status: built
- Example: given a night that stopped at the access step's unmapped values, when
migration.finish_run('failed')runs, thenmigration.v1_auth_usersandmigration.v1_auth_identitiesare empty, so no password hash stays at rest. - Refusal: none.
- Who: the migration machinery; BE-DP-29 and the nightly job (#187).
- Source: the CTO on #278 (2026-10-26, finding 1: hashes were emptied by hand, so a stopped night left them there); D50; D15; BE's wording on #328.
R-MIG-10 · The reconcile lists every v1 table and every v1 column that no step claims, until a step claims it or zuki signs it as ignored
Section titled “R-MIG-10 · The reconcile lists every v1 table and every v1 column that no step claims, until a step claims it or zuki signs it as ignored”- Status: built
- Example: given v1 gained a table since the night before that no step reads, when the reconcile runs, then it lists the table by name under its check, and the night still finishes (unlike R-MIG-02, a new table or column stops nothing). A column added to a table a step reads, which the step doesn't read, is listed the same way. Once a step claims it, or zuki signs it in migration.accepted_differences with a reason (R-MIG-06), it is no longer listed. A table made by a v1 bug fix is treated like any other, and is listed every night until zuki signs it as ignored. A table whose name contains
backup, in any case, is signed as ignored by its name alone, as v1's admins keep making them: given a night whose snapshot holds 28 tables whose name containsbackup, when the reconcile runs, then it lists none of them by name and prints one line with how many there are, never their names, as several name a person (D15); a backup table v1 makes tomorrow is covered the same way, with no new signature. A table whose name containsbackupthat a step claims isn't signed by the pattern: its columns the step doesn't read are listed like any other's. A step claims a table or a column when it reads it; the photo copy claims a table or a column whose values name v1's files. A table signed as ignored because it is empty (a reason that startsempty:) is ignored only while it has 0 rows: givenstock_opname_scanssigned while empty, when a night's snapshot holds rows in it, then the reconcile lists it again astable stock_opname_scans, signed while empty, now with rows, a key that isn't signed, so zuki sees it; on a night it is empty again, it isn't listed. - Refusal: none.
- Who: the migration machinery's reconcile (R-MIG-05), over every table and column of v1's public schema in the night's snapshot (R-MIG-01); every domain step, by what it reads. zuki signs the tables whose name contains
backuponce, by that pattern, rather than one by one. - Source: D75 (v1 is still developing: the reconcile says the night v1 gains a table or column no step reads, not at cutover); D18; #323; the CTO's empty-table safeguard and BE-DP-33's signatures on #324 and #362 (zuki, 2026-10-28); zuki on #591 (2026-11-10: the tables whose name contains
backupare signed by pattern and printed as a count; D15; D75, v1 keeps making tables). The example widens; the ID and the rule stay.
R-MIG-11 · The access step doesn't run while a v1 deny maps onto no v2 code, unless that deny is signed
Section titled “R-MIG-11 · The access step doesn't run while a v1 deny maps onto no v2 code, unless that deny is signed”- Status: built
- Example: given a v1 viewer whose allowed_perms_denied holds etle:read, which maps onto no v2 code until #562, when the access step runs, then it is refused, and migration.dropped_denies() lists the login's id and etle:read. Once zuki signs that login's etle:read as an accepted difference under the check
access dropped denies(R-MIG-06), the step runs and the login has no override for it. A deny of aktivasi:read or aktivasi:write still gives a deny of payment:read or payment:write, as each maps onto a code. A grant that maps onto no code is only dropped, as before (R-ACC-71): dropping a grant gives less, never more. - Refusal: migration.dropped_deny.
- Who: the migration's access step (data phase). Only the access step is refused; the other steps run.
- Source: zuki, 2026-11-06 (option 1), on #553: v1's allowed_perms and allowed_perms_denied share one value_map field, so a name mapped onto no code drops its deny too, and the login would see what v1 hid. zuki checked v1 on 2026-11-06 (#187): two logins have dropped denies, and zuki signed all three until #562 builds their codes. A viewer's etle:read shows nothing, as the viewer is also denied payment:read, which opens ETLE in v2; an admin's etle:write and rental:write give nothing, as the admin is also denied payment:write and v2 has no Rental Harian write; R-MIG-02, R-MIG-06, R-ACC-71.