Repository navigation
refactor(migrations): settle one home for the English-key backfill SQL - #1245
Conversation
Three migrations on main carry a byte-for-byte hand copy of this jsonb
machinery, and the copies drifted. One documented `? key` as the clause
that keeps a non-object out of the delete, which is false: measured
against Postgres, `? key` is true for a string scalar equal to the key
and true for an array holding it, so only `jsonb_typeof(col) = 'object'`
excludes both shapes.
The helper parameterises the global's table base as well as the leaf
group, since the carve-out holds for all three translations globals. It
lands with no caller: the migrations already on main hold their
`payload_migrations` row and never re-run, so rewriting them changes
nothing a database will see. The first caller is the next such
migration.
The spec is an integration spec because both guards are Postgres
semantics rather than SQL text. Each guard was removed in turn and
watched fail: without the write guard `||` turns the group into
`["menu", {...}]`, and without the delete guard a scalar raises
`cannot delete from scalar` while an array silently loses its element.
Refs: #1242
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVzAsZh9fkbzqHumf5
This paragraph is the one doc that states the guard, so it is where the next hand-written copy is read from — and it stated the clause that does not work. `? '<key>'` is true for a string scalar equal to the key and for an array holding one, so it excludes neither shape the delete has to refuse. Refs: #1242 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVzAsZh9fkbzqHumf5
Review pass over the branch. The boolean that chose between one SQL fragment and an empty one travelled through a type field, a literal and a four-line helper. Putting the fragment in the target literal deletes all three and puts both `_<base>_v` spellings next to each other, where they can no longer disagree. `withSchema` now returns its body's value, so the spec reads its results back through the same seam the code under test writes through. That drops a hand-rolled schema qualifier and a copy of withSchema's own guard message. The spec also spells the three table names out instead of re-deriving them from the base: they are what the module's derivation has to produce, so deriving them twice would let both sides be wrong together. The `? key` rebuttal now lives once, in `src/globals/AGENTS.md`, with each function keeping only its own consequence. That paragraph also names `20261118_231500` as still carrying the wrong guard, because a reader copying the nearest predecessor arrives from the migration, not the prose. Refs: #1242 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVzAsZh9fkbzqHumf5
The spec's guard comment said each case picks a key the stored value does not equal. That is true of the write path and inverted for the delete one: `col ? key` reaches the row only when the value DOES hold the key, so a non-matching key there would leave `jsonb_typeof` dead weight and the case would pass with the guard removed. Checked both directions. And `20261118_231500` is not unrunnable, only un-scheduled: its `up` is applied everywhere it will ever run, but `migrate:down` still reaches its `dropKey`. Refs: #1242 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVzAsZh9fkbzqHumf5
|
🚅 Deployed to the SahajCloud-pr-1245 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
1 question for the reviewer, one per thread.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is no bigger than #1242: one 83-line module, its spec, and the doc line criterion 5 names. The three migrations are byte-identical to main, and the SQL matches 20261118_210000 clause for clause on both paths. Landing caller-less is decision A, recorded before you typed implement.
Two for you. src/AGENTS.md rule 3 says src/lib/ holds only code shared across 2+ consumers; this module has zero, and lib-boundary.spec.ts passes it only because its predicate is !== 1. Either the rule gains a line or the spec a KNOWN entry. Second, the ## Change outline shows jsonb_typeof on the delete path as an addition, but two of the three copies already carry it — only the drifted 231500 does not. Outline-first, that reads as a tightened guard rather than the majority copy adopted.
Findings
should-fix—tests/utils/withSchema.ts:18— this diff makes it the int lane's raw-SQL seam; two specs still hand-roll it.should-fix—src/globals/AGENTS.md:314— five new doc lines narrate one frozen file the sentence below already covers.should-fix—src/lib/translations/englishKeyBackfill.ts:81— Streamline:AND col ? keyguards nothing pastjsonb_typeof.consider—src/lib/translations/englishKeyBackfill.ts:7— Streamline: the header re-derivessrc/migrations/AGENTS.md's fact.
What was checked
Ticket #1242 and its comments; the whole diff; englishKeyBackfill.ts, withSchema.ts, the spec, lib-boundary.spec.ts, src/AGENTS.md and the three migrations read whole. Every path the body names exists on the branch. No ## Preview link, and fixture.surfacePaths is untouched. No contractSync source in the diff. version_<main> holds for 119 leaf columns in the snapshot, not the 116 the thread says. Streamliner: 6 pieces, 6 kept, 2 findings, 1 sketch dropped.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The ⚠ re-derived why a named migration never re-runs, which `src/migrations/AGENTS.md` § "The failure this design prevents" already owns. A second home for that fact is a second thing to keep true. The instruction, the ⚠ and the #1242 breadcrumb stay. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZAgjYYrBqVPHXsmsU
Five lines narrated why 20261118_231500 is left as it deployed. That its `up` is spent belongs to `src/migrations/AGENTS.md`, and the instruction below already says to copy the helper rather than any predecessor. What a reader cannot re-derive is that its `down` guards on `?` alone, so a `migrate:down` through it can abort. That stays. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZAgjYYrBqVPHXsmsU
Both specs qualified a table themselves, one by building `"<schema>"."events"` for `sql.raw` with the interval and the id interpolated, the other by casting `payload.db` to reach `pool.query`. The seam that answers both is now generic, so neither needs its own copy of the search_path rule, and both statements become parameterised. Each write was neutralised in turn and watched fail — the 0-day interval dropped both `a class taken down` cases, and an id nobody holds dropped the non-bare-host refusal. Neither case passes with its setup gone. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZAgjYYrBqVPHXsmsU
Three specs reach it now and no guide mentioned it, so the next spec writing raw SQL would hand-roll a qualifier again — which is what both specs adopted in this branch had done. The gotcha a reader cannot derive is that getting it wrong is silent: the statement reads `public`, finds no tables, and the case passes having changed nothing. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZAgjYYrBqVPHXsmsU
|
Three threads adopted, one rebutted. One still waits on you. Adopted
Rebutted
From the review body. The The question thread is unchanged, B built. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…english-key-backfill
Merging origin/main brought #1246, which deletes every a11y leaf group from wm-web-translations. The spec seeded common.a11y, so its three table reads hit a column that no longer exists and all seven cases failed on the merged tree. common.general is the live sibling, and loading / show_more are both declared, so the seed stays a write additionalProperties: false accepts. Both guards were neutralised again on the new group and watched fail: the write path lost two cases, the delete path two. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWSq14etEawvvxGuCV
Option A, answered on the question thread. `group` is one column name, and
`targets` builds `version_${group}` beside the `_${table}_v_locales` it
already derives, so a mis-paired group stops being expressible: a copy-paste
from another group previously wrote the key into a different leaf group,
Postgres raised nothing, and the stored undeclared key then refused every
later save of the global.
The rule holds for every leaf column in all three globals on the merged base
— 13 + 43 + 50 jsonb columns, each with its version_ pair, none unpaired in
either direction. 20261121_035100_atlas_drop_a11y_keys, which arrived with
the merge, spells the same derivation as `prefix: 'version_'`.
Dropping the prefix from the derivation fails all seven spec cases.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWSq14etEawvvxGuCV
|
Option A built. One thread, now resolved. Adopted
Criterion 1 on #1242 now reads the derived form, marked Base merged clean, with one consequence. #1246 deletes every Re-measured on the merged base: Lean gate ✓, 3852 unit tests. Int specs 7 + 22 + 25. Contract step exit 0, no files. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`src/lib/translations/` held the English-key backfill SQL next to five runtime readers of the same globals, so nothing in the tree said which code a hand-written data migration may reach. `src/lib/migrations/` is that signal, and it is the only folder a file in `src/migrations/` imports from. The one-consumer rule gains a third exemption for it. A migration is frozen the moment it merges, so "move it beside its consumer" has no answer here: the consumer is do-not-augment generated output, and the second consumer is a migration nobody has written yet. That retires the `lib-boundary` trap this PR's notes flagged for whichever PR adds the first caller. Verified in all three directions: the exemption passes with a lone `src/migrations/` consumer, the rule still fails without it, and a lone consumer outside `src/migrations/` still fails. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZe5FjS67YwRqMvS6A
|
One thread adopted, now resolved. Adopted
Watched in all three directions: the exemption passes with a lone Base already current. Lean gate ✓, 3852 unit tests. Int spec 7. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`down` guarded each delete on `? key` alone. That is true for a string scalar equal to the key and for an array holding one, so neither shape is excluded — and `-` on a scalar raises `cannot delete from scalar`, which aborts the boot migration rather than failing one statement. The file's own comment claimed the opposite. #1245 settled one home for this SQL, with both guards, and `tests/int/english-key-backfill.int.spec.ts` exercises them against Postgres rather than against the generated statement. This migration is unmerged, so it can be that module's first caller instead of a fourth hand copy; the ones already on `main` keep theirs, since a name with a `payload_migrations` row never runs again. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWvi3CWG5jHZuC5Rsg
Summary
addEnglishKey/dropEnglishKeymove tosrc/lib/migrations/englishKeyBackfill.ts, parameterised by the global's table base so all three translations globals can use them.src/lib/migrations/is a new folder, and the one a file insrc/migrations/may import from. The one-consumer rule gains a third exemption for it, which retires thelib-boundarytrap this body used to flag.jsonb_typeof(col) = 'object', which is what two of the three copies already do.20261118_231500is the one that drifted to? '<key>'alone, andsrc/globals/AGENTS.mdtold that story too — the doc is corrected here, the frozen migration is not.withSchemareturns its body's value, so a case can read results back through the seam it writes through. It had no caller at all before this.withSchema, andtests/AGENTS.mdnames it as the lane's one seam for raw SQL.groupis one column name, and the module derivesversion_<group>beside the versions table it already derives. A mis-paired group is no longer expressible.origin/mainmerged in. refactor(translations): no global declares a screen-reader-only string #1246 deletes everya11yleaf group fromwm-web-translations, which the spec seeded, so the spec moves tocommon.general.Change outline
The one rule the three hand copies each spell for themselves, now spelled once.
tableis the global's table base andgroupis the main locales table's column; the three table names and the versions column come off them.Files
src/lib/migrations/ # new folder — the only one src/migrations/ imports from +└── englishKeyBackfill.ts # addEnglishKey / dropEnglishKey: the jsonb writes, for any of the three globals src/lib/translations/ # unchanged — five runtime readers of the same globals ├── clientEnglishFallback.ts └── schemaWalker.ts src/migrations/ ├── 20261118_210000_wm_web_new_tab_one_key.ts # unchanged — carries both guards ├── 20261118_231500_wm_web_a11y_landmark_keys.ts # unchanged — the drifted copy, `?` alone ├── 20261118_233000_wm_web_menu_key.ts # unchanged — carries both guards ~└── AGENTS.md # what a migration may import ~src/AGENTS.md # the folder, and the third exemption tests/ ├── int/english-key-backfill.int.spec.ts # new — both guards, both tables ~├── int/event-calendar-feed.int.spec.ts # drops its own `"<schema>"."events"` + sql.raw ~├── int/region-canonical-url.int.spec.ts # drops its `payload.db as unknown as { pool }` cast ~├── unit/lib-boundary.spec.ts # the third exemption ~├── utils/withSchema.ts # returns the body's value ~└── AGENTS.md # the raw-SQL seam, namedBehaviour — the two guards, and what each refuses
Byte-identical SQL to
20261118_210000and20261118_233000, which carryjsonb_typeofon both paths already. What changes is that one statement now covers every global. The-line below is20261118_231500alone.addEnglishKey(db, { table, group, key, en }) for each of <base>_locales.<group> (every row) and _<base>_v_locales.version_<group> (latest only) UPDATE … SET col = coalesce(col,'{}') || jsonb_build_object(key, en) WHERE _locale = 'en' AND jsonb_typeof(coalesce(col,'{}')) = 'object' # `||` on a scalar builds an array AND NOT coalesce(col,'{}') ? key # never overwrite a chosen word dropEnglishKey(db, { table, group, key }) for each of the same two columns (every locale, every version) UPDATE … SET col = col - key - WHERE col ? key # 20261118_231500's guard, and it is wrong + WHERE jsonb_typeof(col) = 'object' # `-` on a scalar raises; on an array it edits AND col ? key # the rows to rewrite, not the whole tableContract — the paragraph the next copy is read from
src/globals/AGENTS.md, "Retiring a key needs a data migration". It was the only doc stating the guard, and it stated the one that does not work.Preview
No preview surface — the diff touches none of
fixture.surfacePaths.Test results
.claude/skills/pr-prep/check.sh— lint, format, typecheck (src), typecheck (tests), 3852 unit tests in 286 files, 134 s on the final treeenglish-key-backfill(7),event-calendar-feed(22),region-canonical-url(25)tests/unit/lib-boundary.spec.ts: ✓, with noKNOWN_SINGLE_CONSUMERentry. The new exemption was watched in all three directions — it passes with a lonesrc/migrations/consumer, the rule still fails without it, and a lone consumer elsewhere still failstimeout 300 pnpm db:migrations:create probe --skip-empty < /dev/null→ exit 0, no files written. Nothing here changes the schemaEach guard was removed in turn and watched fail, before the fix was restored. First on
common.a11y, then again oncommon.generalafter the merge moved the fixture:cannot delete from scalaron the string scalar;[]on the array, silently — 2 casesversion_prefixEach adopted spec's raw write was neutralised the same way, because a setup that silently does nothing leaves its case asserting nothing:
make_interval(days => 0)a class taken downcases — the 90-day window and the republishWHERE id = <nobody>refuses a verified host that is not a bare hostFixture: the spec uses
common.generalonwm-web-translations, which stores ascommon_general/version_common_general, and the declared keysloadingandshow_more— so its seed is a writeadditionalProperties: falseaccepts. It started oncommon.a11y, which #1246 deletes; the three table names and the versions column are spelled out rather than re-derived, so the spec pins what the module's derivation has to produce.Manual verification
Nothing. The module has no caller yet, so no running surface changes.
Notes for reviewer
src/lib/migrations/on its own would be a naming convention;lib-boundaryexempting it is what the next migration's import line actually buys. Without it that PR would need aKNOWN_SINGLE_CONSUMERentry — a list the spec says should only shrink.latestOnlyfragment is built for both targets, anddropEnglishKeyinterpolates neither. Same shape as thelatestOnly: truefield it replaced, so no new trap, but worth a look.881c4a7. Criterion 1 on refactor(migrations): settle one home for the English-key backfill SQL #1242 is updated to the derived form.Detail — review findings dismissed, and what was left out
Four
/simplifylenses plus/code-review high, then the adversarial review.pr-review-toolkitis not available to a routine. Security review skipped: nosecurityReview.triggerPatternpath in the diff.comment-lint.mjs: clean.Dismissed:
Executorwith the identical unexported type insrc/lib/atomicWrites/appendLogEntry.ts. Sharing means either exporting a two-line type out of a folder its own guide closes ("no barrel"), or a newsrc/libfolder for two lines. This one isPick<MigrateUpArgs['db'], 'execute'>, derived from Payload's type rather than hand-written, so it tracks a Payload bump; the other does not.appendLogEntry) is a collection with a version array, not a global with a locales table. Two unlike callers is not a shared rule yet.coalesce(col,'{}')occurrences into a local. All four are load-bearing and it is the one deliberate fidelity to the shipped copies.AND col ? keyfromdropEnglishKey, sincejsonb_typeofalready excludes every shape that raises. It is the row filter, not a guard: without it every call rewrites every row of_<base>_v_locales, one new tuple and its WAL each, in a boot migration, growing with version history. Both non-drifted copies carry the pair.Adopted from the adversarial review: the two specs above (reversing an earlier dismissal of exactly that — the seam is built here, so it is not a follow-up), and two comment streamlines, the module header and the
src/globals/AGENTS.mdparagraph, each cut to the fact a reader cannot re-derive.Corrected after review, worth naming because both were mine: the spec's guard comment was inverted for the delete path (
col ? keyreaches the row only when the value does hold the key, so a non-matching key there would have leftjsonb_typeofdead weight — checked both directions); and the doc claimed20261118_231500can never run again, when only itsupis spent andmigrate:downstill reaches itsdropKey.Measurements. The
version_<main>naming option A holds for every leaf column in all three globals, with no exception in either direction. Counted on the merged base's newest snapshot,20261121_035100_atlas_drop_a11y_keys.json, over jsonb columns alone: 13 + 43 + 50, each with itsversion_pair, none unpaired. #1246 tookwm_web_translationsfrom 23 to 13. Counting jsonb excludesversion__status, the per-locale publish flag, which is an enum — the earlier 119 counted it as a leaf group.20261121_035100_atlas_drop_a11y_keys.ts, which arrived with the merge, spells the same derivation asprefix: 'version_'. The spec costs ~6 s, of which ~2 s iscreateTestEnvironment().Closes #1242