Skip to content

fix(app-cards): localize the destination discriminator beside its targets - #1010

Merged
sydevs-bot merged 7 commits into
mainfrom
claude/fix-1001-localize-destination
Oct 21, 2026
Merged

sydevs-bot merged 7 commits into
mainfrom
claude/fix-1001-localize-destination

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • destination now 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`)
app_cards.default_destination            → app_cards_locales.default_destination
app_cards.starting_soon_destination      → app_cards_locales.starting_soon_destination
app_cards.live_now_destination           → app_cards_locales.live_now_destination
_app_cards_v.version_*_destination       → _app_cards_v_locales.version_*_destination

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.

 up()                                         src/migrations/20261021_014535_localize_app_card_destination.ts
   ADD COLUMN × 6, nullable                   # generated
+  INSERT INTO *_locales (_locale='en', …) SELECT FROM the base table
+    WHERE any of the three destinations is non-NULL
+    ON CONFLICT (_locale, _parent_id) DO UPDATE
   DROP COLUMN × 6                            # generated
 down()
   ADD COLUMN × 6 on the base tables          # generated
+  UPDATE base SET … FROM *_locales WHERE _locale = 'en'
+    AND that row holds at least one destination
   DROP COLUMN × 6 on the locale tables       # generated

INSERT, not the UPDATE … FROM that 20260911_235823_pages_app_cards_localize_status.ts uses: a card created with the admin in French carries a base destination and no en locale row, so an update would copy that card's value nowhere.

Preview

  • App cards list — the collection whose columns the migration moves
  • Any card's editor — switch the admin locale and Destination now holds a value of its own

Data: not seeded yet. previewUrl.seed is 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-audience answers with a different destination per locale where an editor has set one. No generated type changed — src/payload-types.ts is 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

  • New migrations, two:
  • Impact: app_cards, app_cards_locales, _app_cards_v, _app_cards_v_locales. Six enum columns move; every value is copied into the en row 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).
  • Reversible: yes — down() copies the en value 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 no en row, and a card with no destination at all. Every value round-trips through up() and down() unchanged. The same fixture with the backfill removed loses all three destinations — which is what the generated delta ships.

Test results

Both new cases were watched failing against the unlocalized column first, one per direction: expected 'lecture' to be 'url' and expected 'url' to be 'meditation'.

Manual verification

  1. On the preview, create an app card with Destination = Album, pick an album, and publish it.
  2. Switch the admin locale to French, set Destination = URL with a French URL, and save.
  3. Switch back to English: Destination still reads Album, and the album is still picked.

Notes for reviewer

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.md asks to be surfaced rather than decided silently. It was rejected because the second migration's DROP COLUMN is 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 single INSERT … SELECT over 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 en alone is backfilled. The old column was readable as every locale's value only through the English fallback, which buildPayloadLocales() gives all 18 non-English locales. destination is never used in a where, 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 and tests/AGENTS.md lists localization fallback under what not to test. From the /simplify pass: bounding the version backfill to latest = true (versions.maxPerDoc: 5 already caps that 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 English locale's own target alone); moving the storage-level case into pages-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 .json conflicted, and 20261021_024228_merge_1002_main_snapshot regenerates it. A migrate:create probe after that file writes nothing. No migration has landed on main since, so that snapshot is still the current one.

Closes #1001

`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
@railway-app

railway-app Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-1010 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Oct 21, 2026 at 2:50 am UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 question for the reviewer, one per thread.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/collections/AppCards/AppCards.ts Resolved
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 21, 2026
@sydevs-bot

sydevs-bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 15:50Z address-review · attempt 1 · session · done
  • 15:50Z address-review · attempt 1 · session
  • 03:11Z address-review · attempt 1 · session · done
  • 03:11Z address-review · attempt 1 · session
  • 03:03Z review-pr · attempt 1 · session · done

Written 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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1010 October 21, 2026 02:28 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main. Four doc hunks conflicted, all the same unit-lane count line.

Took main's 217 files / 2792 tests in all four. #996 landed the 217th spec, and this branch adds no unit spec, so main's figure already counts both sides. The merged lane measured 217 / 2792 — 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 affected. No migration landed since the merge base, so the snapshot parent is unchanged.

Lean gate green. app-cards-for-audience and translations-field int specs: 60 passed. The body's Test results line still quotes the pre-merge 216 / 2788.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 21, 2026
#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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1010 October 21, 2026 02:47 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main (#1002). Every hunk keeps both sides.

  • destinationFields() — destination and meditation both carry localized: true now. The comment calling every relationship target shared counted meditation among them, so it names only page, lecture and album.
  • app-cards-for-audience.int.spec.ts — both branches added a per-language destination describe. One block now, holding main's meditation case and this branch's two. 35 pass.
  • src/migrations/index.ts — both branches' migrations, in timestamp order.
  • 20261021_024228_merge_1002_main_snapshot is new, and snapshot-only. 20261021_014535 left the newest snapshot without the columns fix(translations): localize five per-language fields admins edit #1002 moved, so migrate:create re-emitted all of them. A probe after it writes no files.

Lean gate green: 217 files, 2792 tests.

Two body lines are stale: meditation is localized on main now, and Test results predates this merge.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 21, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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 says meditation stays shared and prices option B at four relationships. #1002 localized it.
  • should-fix — the PR body, four claims the diff contradicts: the ## Summary bullet carrying #1009's doc re-count (no Markdown in the diff), ## Test results at 216 / 2788 (the lane is 217 / 2792), ## Migration naming one migration where there are two, and ## Notes for reviewer saying #1002 is unmerged.

What was checked

  • #1001's three criteria. Both directions are covered: an fr read at fallbackLocale: false, and the endpoint's en read after a French edit.
  • destinationFields() whole, and all five admin.condition readers of destination. forAudience.ts selects it per tab and never filters on it, so localizing it changes no query.
  • Both migrations against the whole chain. index.ts is in timestamp order with 20261020_170450 ahead of both, and every statement 20261021_024228 emptied is in that file. Both locale tables carry *_locale_parent_id_unique, so the ON CONFLICT infers.
  • Both ## Preview links answer 200, so the migration applied on boot. The collection is empty, as stated.
  • No src/payload-types.ts change against origin/main, so no types:cms consumer is affected.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/collections/AppCards/AppCards.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 21, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Base is current: main (5e302d7) is an ancestor of this head. Nothing pushed — both findings were about the written record.

Adopted — the stale premise on the A/B/C thread. meditation carries localized: true since #1002, so the question is restated: A already covers it, B is three relationships. Thread resolved.

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

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 21, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 21, 2026 03:19
@sydevs-bot
sydevs-bot requested a review from Ardnived October 21, 2026 03:19
@sydevs-bot
sydevs-bot enabled auto-merge October 21, 2026 03:19
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Oct 21, 2026
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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

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. app-cards-for-audience.int.spec.ts, 35 pass.

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

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 21, 2026
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Oct 21, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit d02cceb Oct 21, 2026
33 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-1001-localize-destination branch October 21, 2026 16:40
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 21, 2026
sydevs-bot pushed a commit that referenced this pull request Oct 21, 2026
…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
sydevs-bot pushed a commit that referenced this pull request Oct 21, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(app-cards): localize the destination discriminator beside its targets

3 participants