Admit upstream's loan migration beside the fork's

Merged
JA
2mo ago
+50-10

Summary

Part of #184 (phase 1 of the 2026-09-30 reconciliation plan: migration hygiene, no engine change).

Two class-name collisions between the fork's loan migrations and upstream's:

ClassForkUpstream
AddVariableRateTrackingToLoans20260831160656 (also creates loan_amortizations)20260908145118 (two loans columns)
AddDayCountConventionToLoans2026090700000020260918210000, in we-promise/sure#3639, not merged yet

With both files of a pair present, db:migrate raises DuplicateMigrationNameError, so every weekly sync has been deleting upstream's 20260908145118. #3639 would cause the second collision on the first sync after it merges.

  • The fork's two migrations are renamed, file and class: CreateLoanAmortizationsWithVariableRateTracking and AddForkDayCountConventionToLoans. Rails records migrations by version, so a database that ran them under the old names doesn't run them again.
  • Upstream's 20260908145118 is admitted with if_not_exists on both columns and an empty down. Those are its only differences from upstream's copy. On a fork database it runs and changes nothing, and rolling it back changes nothing either.

Scope and dependencies

  • Issue: #184 (phase 1)
  • Parent PR/branch, if stacked: none. Base main. The #188 fork PR (#397, thirty_360) stacks on this branch.
  • Intentionally out of scope: widening chk_loans_day_count_convention, which the phase plan put in phase 1. It moves to the #188 change, together with the engine support for thirty_360, because the model can't accept the value before then. #3639's own migration isn't admitted here, since it hasn't merged upstream; once it does, its name collision is already defused, and its guards (if_not_exists, a name-matched constraint check) skip on a fork database.

Evidence checklist

  • Each issue in this PR has its own acceptance criteria and no unrelated issue work is included.
  • Contract rows touched by this change name existing tests. (Not applicable: no engine code.)
  • Any gate test has an observed failing mutation transcript attached.
  • Fixtures used as evidence assert internal consistency. (Not applicable.)
  • Financial calculations use BigDecimal and documented rounding points. (Not applicable.)
  • De-identification uses token-shape allowlists; no personal data is included.
  • Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.

Validation

A deployed fork database. A scratch database loaded from fork main's schema (466 versions recorded, including 20260831160656 and 20260907000000):

  • db:migrate:status on this branch: one pending migration, 20260908145118.
  • db:migrate: both add_column ... if_not_exists: true calls run and change nothing.
  • The schema dump afterwards differs from the committed db/schema.rb only in four check constraints outside loans, where this local PostgreSQL prints ARRAY['a'::character varying::text, …] for ARRAY[…]::text[]. That's the same noise #264 recorded. The loans table and the version stamp are unchanged.

A fresh database. db:drop db:create db:migrate from zero runs the whole chain clean and dumps the committed schema, apart from the same formatting noise.

Rollback. db:migrate:down VERSION=20260908145118 leaves both columns in place. With a reversible change instead, it dropped both.

Mutations, each reverted:

M1 drop if_not_exists from 20260908145118
   PG::DuplicateColumn: ERROR:  column "variable_rate_schedule" of relation "loans" already exists
M2 keep the fork's old class name beside upstream's file
   ActiveRecord::DuplicateMigrationNameError
M3 reversible change instead of up + empty down
   migrate:down leaves neither start_date nor variable_rate_schedule

bin/rubocop on the three migrations: no offenses. Checked against upstream AGENTS.md: historical migration versions are left intact; only class and file names change.

Brought up to date with main (2026-10-12), as upstream AGENTS.md asks before review. 278815373 merges main at 3727ee4e0. That brings in only main's own commits: 513ee49c6, CI's service and Codacy images from public mirrors, and 3727ee4e0, the mirror schedule. Those touch .github/workflows/ and CLAUDE.md. Everything else is byte-identical to 227d948c9 (git diff 227d948c9 278815373 -- . ':!.github' ':!CLAUDE.md' is empty), so the PR's own diff is unchanged: 4 files, +50 / −10. Re-checked today against upstream AGENTS.md on mirror/upstream-main (d55eac220): migration versions are intact, both commit subjects are imperative and at most 72 characters, the PR links its issue (Part of #184), and the branch is now up to date.

Review findings

  • cubic, rollback drops the columns: valid. Fixed in 227d948. The admitted migration now has an explicit up and an empty down. The fork's earlier 20260831160656 creates both columns and drops them on its own rollback, so reversing add_column here would drop them while that migration still counts as applied (M3 above).

  • Gatekeeper light review (comment 6091128411): DRAFT_ON_TRACK, no material findings. Its observation (the admitted migration differs from upstream's by the guards and the empty down, both documented in the file) needs nothing further. Its recommendation to confirm the admission survives the first weekly sync (the add/add on 20260908145118) is the "Next sync" item under Risks.

  • "code master" review (comment 6106038073), HOLD, on 227d948: nothing to change. Each finding was checked against this head:

    1. Migration[8.1] fails on Rails 7.2: declined. The app runs Rails 8.1.3.1 (Gemfile.lock: rails (8.1.3.1)), and 39 migrations already on main declare [8.1]. The [7.2] on the fork's older migrations is the version each was written under, and Rails accepts any version up to its own. The [8.1] is upstream's own line, kept so the admitted file differs from upstream's only by the guards and the down.
    2. if_not_exists hides a column with the wrong type: declined; not worth its code. The only migration that creates these columns on a fork database is 20260831160656. It creates them exactly as this one would: variable_rate_schedule as jsonb, default: {}, null: false, and start_date as date. db/schema.rb records the same. A mismatch would need a hand-edited production schema, and checking types inside a no-op migration would be more code than the case is worth.
    3. schema.rb is out of sync and CI would fail: declined.
      • This PR changes no table, so db/schema.rb has nothing to record. The version stamp 2026_10_08_100000 is already later than 20260908145118.
      • The dump difference is this machine's PostgreSQL 16.15 printing four pre-existing constraints outside loans differently, as #264 recorded. It isn't caused by these migrations.
      • CI builds its databases with db:schema:load (ci.yml, lines 155 and 269) and runs no drift check.
    4. The weekly sync will keep deleting the file: declined. The sync is a manual merge; upstream-sync-reminder.yml says "It never merges". With this PR, the fork's file sits at upstream's exact path (git ls-tree origin/mirror/upstream-main db/migrate/ lists 20260908145118_add_variable_rate_tracking_to_loans.rb). So the first sync after it meets a one-time add/add conflict on that one file, not a DuplicateMigrationNameError. The "Next sync" item under Risks says how to resolve it.
  • Nightly review (comment 6120530229), READY TO MERGE, on 227d948: no findings. Its one note, that the next upstream sync must keep the guarded fork copy of 20260908145118, is already the "Next sync" item under Risks.

  • CodeRabbit full review, on 278815373, requested on 2026-10-12. CodeRabbit gives this repository no automatic reviews (fewer than 10 stars). It made no actionable comments, rated the merge risk Minimal, and noted that the next upstream sync must keep the guarded migration, which is the "Next sync" item under Risks. One pre-merge check failed: docstring coverage at 25%, against 80%. Declined: it is CodeRabbit's generic heuristic, and this repository has no docstring convention for migrations.

  • Full Gatekeeper review (comment 6126076769, part 2 6126107783), APPROVE, on 278815373 (the current head): risk MEDIUM, confidence HIGH, CI passing, no material findings. Its three observations agree with this description and need no change:

    • [8.1] is valid on Rails 8.1.3.1, as the "code master" reply above says;
    • if_not_exists and the empty down are correct;
    • schema.rb is rightly unchanged, and widening the constraint belongs to #188.
    • Part 2 rates the test evidence ADEQUATE and the requirements ALIGNED. Its residual risk, the next sync's add/add conflict on 20260908145118, is the "Next sync" item under Risks.
  • Full Gatekeeper re-review (comment 6126831053, part 2 6126872752), APPROVE, on 278815373: a forced re-review of the same head, re-verified against the files, Gemfile.lock and CI. No material findings; test evidence ADEQUATE, requirements ALIGNED, and the same "Next sync" residual risk. Nothing to change.

Review responses are recorded here rather than as thread replies, because replies posted from this session get an assistant footer appended, which this repository's attribution rule forbids.

Risks, blockers, and follow-up

  • Deploying: on an existing fork database db:migrate records 20260908145118 and changes nothing.
  • Next sync: git will see upstream's 20260908145118 as an add/add on the same path. Keep the fork's copy (with if_not_exists and the empty down), which is a content resolution, not a duplicate-name error.
  • Next unblocked: #188 on the fork (#397: thirty_360 support and the constraint widening).