Repository navigation
fix(app-cards): localize the destination discriminator beside its targets - #1010
Conversation
`destination` decided which target column a card reads while holding one value for all 19 locales, and `url` — the target it selects — has been localized since it was written. So a French editor switching a card from Page to URL flipped the discriminator for every locale and wrote the URL into the `fr` row alone: English then resolved `destination: 'url'` against a NULL `en` url and the card reached the app with no destination. `GET /api/app-cards/for-audience` selects all three tabs' `destination` beside their targets, so the mismatch did not stop at the admin. The migration's backfill is hand-written, and the generated delta loses every card's destination without it. It inserts rather than updates, unlike `20260911_235823_pages_app_cards_localize_status.ts`: a card created with the admin in French carries a base `destination` and no `en` locale row at all, so `UPDATE … FROM` would copy that card's value nowhere. Both directions were run against a scratch Postgres seeded in the pre-migration shape — an `en`-created card, a French-created one with no `en` row, and a card with no destination — and every value round-trips through `up()` and `down()` unchanged. `page`, `lecture` and `album` stay on the base row: those documents carry their own localized fields, so one reference serves every locale. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01893M4a2CEaHw3Zk99WmfRQ
`tests/unit/perf-figures-pinned.spec.ts` compares PERF.md's recorded file count with the specs on disk, and #1008 added `signin-token.spec.ts` without re-counting — so the unit lane is red on `main`, and on every branch cut from it. PERF.md says the counts track the current tree while each timing stays its own session's, so only the counts move: the 78 s figure is still the slowest measurement recorded. Carried here so this PR's CI is green. It also ships on its own, as the one change the red lane needs. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01893M4a2CEaHw3Zk99WmfRQ
Two findings from `/code-review high`. The field comment said "the targets it selects are" per locale, which holds for `url` alone — the relationship targets are shared on purpose, because each points at a document localized itself. It now says both halves. The "falls back to the English destination" case passed identically against the unlocalized column, so it pinned Payload's own fallback rather than this change, and `tests/AGENTS.md` lists that behaviour under what not to test. The describe's own comment now names the assumption the remaining cases do rest on: `app_cards` carries publish state per locale, which is why a card published at `en` alone reaches the endpoint. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01893M4a2CEaHw3Zk99WmfRQ
`down()` joined on the locale row alone, so it rewrote every card and every version row — writing NULL over NULL for the majority that hold no destination, and churning ~20 and ~28 indexes doing it. It now carries the same "has a value" guard the sibling status migration uses. The first case kept only the direction the endpoint case cannot reach, an English edit arriving at a French card; the endpoint case already proves the reverse end to end, so the duplicate read and its album fixture are gone. Both new cards now take the suite's shared image rather than uploading one each, which is what every fixture in `beforeAll` already does. Dismissed: bounding the version backfill to `latest = true` (`maxPerDoc: 5` already caps the table, and an older version would lose its destination on restore); combining the generated `ALTER TABLE` statements (generated DDL stays verbatim, so it still compares against the snapshot); swapping the meditation fixture for a cheaper one (#1001's third criterion names a meditation, and that assertion also proves the partial French group write left the shared relationship alone); moving the storage-level case to `pages-localize-status.int.spec.ts` (that file's subject is publish state, and splitting the two directions across files hides the pair). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01893M4a2CEaHw3Zk99WmfRQ
|
🚅 Deployed to the SahajCloud-pr-1010 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. |
#996 landed `tests/unit/textbox-block-conditions.spec.ts` on `main` and re-counted the unit lane with it. This branch carried #1009's re-count of the same four docs, so both sides rewrote one line in each. Took `main`'s figures — 217 files / 2792 tests — in all four. The counts are a fact about the merged tree, and this branch adds no unit spec, so `main`'s number already includes everything either side contributes. Measured on the merge: 217 files, 2792 tests, which is what `perf-figures-pinned` reads. Nothing else overlapped. `main` dropped `buildTranslationTabs` from the `@/fields` barrel; `AppCards.ts` takes `mediaField`, `scheduleFields` and `urlField` from it, none of them affected. No migration landed on `main` since the merge base, so the snapshot parent is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AWC3mSf6HECsDNvRiGBmjN
|
Merged Took Nothing else overlapped. Lean gate green. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#1002 localized `meditation` on the same three view tabs, against the same snapshot parent, so every hunk keeps both sides: - `destinationFields()` carries `localized: true` on `destination` and on `meditation`. The comment calling every relationship target shared was true only before #1002, so it now names the three that still are. - `src/migrations/index.ts`: both branches' migrations, in timestamp order. - `app-cards-for-audience.int.spec.ts`: one `per-language destination` describe holding main's meditation case and this branch's two. 35 pass. - `20261021_024228_merge_1002_main_snapshot` is new, and snapshot-only. `20261021_014535` left the newest snapshot without the columns #1002 moved, so `migrate:create` re-emitted all of them — the out-of-order snapshot trap `src/migrations/AGENTS.md` names. A probe now writes no files. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017SW78tqnG85nKPBWAYgUTg
|
Merged
Lean gate green: 217 files, 2792 tests. Two body lines are stale: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the ticket and nothing more: one localized: true, one hand-backfilled migration, the snapshot-only merge file AGENTS.md prescribes, and two int cases. No new layer, no helper, no knob. The backfill is the right shape — INSERT … ON CONFLICT reaches the French-created card an UPDATE … FROM would drop, and down() restores before it drops. I can name no defect in the code.
Both findings are about the written record, which you read first. The one open design question has its own thread, on a premise now wrong.
Findings
should-fix—AppCards.ts:172: the A/B/C question thread still saysmeditationstays shared and prices option B at four relationships. #1002 localized it.should-fix— the PR body, four claims the diff contradicts: the## Summarybullet carrying #1009's doc re-count (no Markdown in the diff),## Test resultsat 216 / 2788 (the lane is 217 / 2792),## Migrationnaming one migration where there are two, and## Notes for reviewersaying #1002 is unmerged.
What was checked
- #1001's three criteria. Both directions are covered: an
frread atfallbackLocale: false, and the endpoint'senread after a French edit. destinationFields()whole, and all fiveadmin.conditionreaders ofdestination.forAudience.tsselects it per tab and never filters on it, so localizing it changes no query.- Both migrations against the whole chain.
index.tsis in timestamp order with20261020_170450ahead of both, and every statement20261021_024228emptied is in that file. Both locale tables carry*_locale_parent_id_unique, so theON CONFLICTinfers. - Both
## Previewlinks answer 200, so the migration applied on boot. The collection is empty, as stated. - No
src/payload-types.tschange againstorigin/main, so notypes:cmsconsumer is affected.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
Base is current: Adopted — the stale premise on the A/B/C thread. Adopted — the review body's four false body claims. Refreshed:
The A/B/C question stays open, waiting on you. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Clean merge: #997, #998 and #1005 touch none of this branch's seven files. - #998 reformatted 250 files under prettier 3.9.10. `pnpm format:check` passes on this branch's own files unchanged, so none needed reflowing. - #1005 added `tests/unit/admin-condition-fields.spec.ts`, which fails an `admin.condition` reading a field the collection never declares. The five readers of `destination` in `destinationFields()` all sit beside it, so localizing it declares nothing away — that spec passes. - Unit lane on the merge: 218 files, 2795 tests, which is what `perf-figures-pinned` reads. No migration landed on `main` since the last merge, so the snapshot parent is unchanged and `20261021_024228` still regenerates the current one. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NbxY7L3ATnBmYYXfrYrM2X
|
Reviewer answered A on the destination-scope question. A is what is built, so no code changed. Thread resolved. Base merged — 973be98, clean. None of #997, #998 or #1005 touches this branch's seven files.
Lean gate on the merge: 218 files, 2795 tests, green in 129 s. Body refreshed where the merge made it false: Test results figures, the answered question, the merge note. No thread is open. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…etention-registry One conflict, in the generated `src/migrations/index.ts`: #1010 added two migrations while this branch added one. Kept all three, in timestamp order, so the array still applies oldest first. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013omVn6xbHvMg1aASCykUQn
The merge put #1010's `20261021_014535_localize_app_card_destination` behind this branch's newer `20261021_152406`, so the newest-by-timestamp snapshot lacked the three localized `app_cards` destination columns. The next `migrate:create` re-emitted all twelve of its statements — DDL that already ships, and whose replay would drop the base columns a second time with no backfill between the halves. Keeps the generated `.json`, which was made on the merged tree and is what heals the chain, and empties the DDL. A probe run after it writes no files. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013omVn6xbHvMg1aASCykUQn
Summary
destinationnow stores a value per locale, so a French edit no longer repoints the English card at a target only French filled in.Change outline
Contract — the discriminator moves to the locale tables
destinationFields()builds one row for each of the three view tabs, so the flag lands on all six stored columns at once.destinationFields() src/collections/AppCards/AppCards.ts destination select(page|lecture|album|meditation|url) + localized: true page / lecture / album # unchanged: shared base-table columns url / meditation # already localized (#1002 moved `meditation`)Flow — what the migration does between the generated halves
The generated delta adds then drops with nothing in between, which loses every card's destination.
INSERT, not theUPDATE … FROMthat20260911_235823_pages_app_cards_localize_status.tsuses: a card created with the admin in French carries a basedestinationand noenlocale row, so an update would copy that card's value nowhere.Preview
Data: not seeded yet.
previewUrl.seedis unset in.claude/workflow.json, so this run had no way to put a card on the preview — both links land on an empty collection until someone creates one, which step 1 of Manual verification does. The migration itself runs on the preview's boot regardless.Contract impact
GET /api/app-cards/for-audienceanswers with a differentdestinationper locale where an editor has set one. No generated type changed —src/payload-types.tsis byte-identical, verified by a forced regeneration — so the response schema, the OpenAPI entry and the two type-syncing consumers (WeMeditateWeb, SahajAtlasWeb) need nothing.Migration
src/migrations/20261021_014535_localize_app_card_destination.ts— the column move and its backfill.src/migrations/20261021_024228_merge_1002_main_snapshot.ts— snapshot only, no DDL.20261021_014535left the newest snapshot without the columns fix(translations): localize five per-language fields admins edit #1002 moved, somigrate:createre-emitted all of them; every statement this file emptied is already in fix(translations): localize five per-language fields admins edit #1002's own migration.app_cards,app_cards_locales,_app_cards_v,_app_cards_v_locales. Six enum columns move; every value is copied into theenrow first, and the other 18 locales read it through Payload's English fallback. Enum types unchanged, no index touched (none ever existed on these columns).down()copies theenvalue back to the base column before dropping the locale columns.Both directions were run against a scratch Postgres seeded in the pre-migration shape: an
en-created card, a French-created card with noenrow, and a card with no destination at all. Every value round-trips throughup()anddown()unchanged. The same fixture with the backfill removed loses all three destinations — which is what the generated delta ships.Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(218 files, 2795 tests) — 129 stests/int/app-cards-for-audience.int.spec.ts, 35 passedpnpm format:check, after fix(build): pnpm generate:types rewrites payload-types.ts after prettier 3.9.10 #998's prettier 3.9.10 bump landed onmainBoth new cases were watched failing against the unlocalized column first, one per direction:
expected 'lecture' to be 'url'andexpected 'url' to be 'meditation'.Manual verification
Notes for reviewer
page,lectureandalbumstay on the base row — each points at a document localized itself.urlalways carriedlocalized: true, and fix(translations): localize five per-language fields admins edit #1002 gavemeditationits own, so a locale picks its own kind of destination, its own URL and its own meditation, but not its own album. Whether an editor should be able to was the question on thelocalized: trueline; the answer is A, so those three stay shared and nothing further is built.enlocale row where none existed, so such a card gains anenkey in itslocale=all_statusmap, taking that column'sdraftdefault. Every other row in that table already holdsdraftfrom feat(pages): adopt versions.drafts.localizeStatus on Pages and AppCards, so a client can read per-locale publish state #718's ownADD COLUMN … DEFAULT 'draft', so this matches the table rather than diverging from it. The alternative —UPDATE … FROM, as feat(pages): adopt versions.drafts.localizeStatus on Pages and AppCards, so a client can read per-locale publish state #718 used — drops a French-created card's destination outright.main's side of every doc hunk, so this branch carries no Markdown of its own, and the unit-lane figures above aremain's.tests/unit/admin-condition-fields.spec.tsfails anadmin.conditionreading a field its collection never declares. All five readers ofdestinationsit beside it in the same row, solocalized: truedeclares nothing away — the spec passes.fallbackLocale: 'en'on every non-English locale, andexperimental.localizeStatuson — both read offtests/utils/testHelpers.tsandsrc/lib/locales/index.ts, not assumed.Detail
Why one migration rather than add-backfill now and drop later. The two-migration shape would leave a rollback window where both columns exist, which is the safer trade
src/migrations/CLAUDE.mdasks to be surfaced rather than decided silently. It was rejected because the second migration'sDROP COLUMNis the only thing that ends the window, and until it ships the base column is a second writable copy of the discriminator that Payload no longer reads — a card edited in that window would diverge from itself. The backfill is a singleINSERT … SELECTover a table of tens of rows, so there is no long-running-migration reason to split it. (The snapshot-only file the #1002 merge added is not that second migration — it carries no DDL.)Why
enalone is backfilled. The old column was readable as every locale's value only through the English fallback, whichbuildPayloadLocales()gives all 18 non-English locales.destinationis never used in awhere, so nothing needs a stored per-locale value to query on — which is what made #718's copy-to-all-19 necessary there and unnecessary here.Dismissed review findings. From
/code-review high: a "falls back to the English destination" case was dropped rather than kept, because it passed identically against the unlocalized column andtests/AGENTS.mdlists localization fallback under what not to test. From the/simplifypass: bounding the version backfill tolatest = true(versions.maxPerDoc: 5already caps that table, and an older version would lose its destination on restore); combining the generatedALTER TABLEstatements (generated DDL stays verbatim so it still compares against the snapshot); swapping the meditation fixture for a cheaper one (#1001's third criterion names a meditation, and that assertion also proves the partial French group write left the English locale's own target alone); moving the storage-level case intopages-localize-status.int.spec.ts(that file's subject is publish state, and splitting the two directions across files hides the pair).The snapshot conflict, resolved. #1002 landed first against the same snapshot parent. The two move different columns, so only the drizzle
.jsonconflicted, and20261021_024228_merge_1002_main_snapshotregenerates it. Amigrate:createprobe after that file writes nothing. No migration has landed onmainsince, so that snapshot is still the current one.Closes #1001