Skip to content

Add plants:sync_common_names for the ECHOcommunity plant migration - #120

Merged
npflood merged 2 commits into
masterfrom
phase1/sync-common-names
Aug 13, 2026
Merged

Add plants:sync_common_names for the ECHOcommunity plant migration#120
npflood merged 2 commits into
masterfrom
phase1/sync-common-names

Conversation

@npflood

@npflood npflood commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Phase 1 of the plant-data ownership migration. Independent of #117, #118 and
#119 — merge in any order.

Syncs common names from ECHOcommunity and sets the primary flag per language.

bin/rails plants:sync_common_names[tmp/common_names.json]              # dry run
APPLY=true bin/rails plants:sync_common_names[tmp/common_names.json]   # write

Why the primary flag is the point

Plant#primary_common_name_for_locale only uses a language when a primary is
set in it, otherwise falling back to English. So a language holding names but no
primary displays English, and the translated names sit unused in the same
table.

That was the state before this: Thai had 1 primary across 186 names. A Thai
reader saw English names for essentially every plant, with Thai names present
and unreachable.

Which name becomes primary

Decided upstream in the migration workspace, where the rules and their reasoning
live together, so this stays a simple apply step. In order:

  1. only one name in that language → it is primary
  2. a name equals the ECHOcommunity title → that one
  3. a name equals a fragment of the title → that one, first fragment wins

Rule 3 does the heavy lifting because ECHOcommunity titles are composites —
"Coriander / Cilantro", "Caigua (achogcha, archucha, caihua…)" — so exact
matching alone resolved almost nothing. Where none of those apply it falls back
to word overlap, then to the lowest-id name, which at least yields a name in
the reader's language rather than English.

Behaviour

Additive for names: missing ones are created, existing ones matched
case-insensitively on (name, language) and never duplicated. Deleting a name
ECHOcommunity no longer lists is an editorial act, not a migration one. The
primary flag is synced in both directions, since exactly one name per language
should carry it.

Rehearsed against staging

57 names created, 1,741 already present, 546 primary flags set, 16 cleared, no
failures. Coverage afterwards:

language before after
Thai 1 / 186 207 / 245
Spanish 53 / 228 107 / 243
French 40 / 105 74 / 108
Chinese 36 / 46
  • 6 new specs
  • Full suite: 2,310 examples, 0 failures
  • Whole-repo rubocop clean

Syncs common names from ECHOcommunity and sets the primary flag per language.

Why primary matters: the API only uses a language when a primary is set in it,
otherwise falling back to English. A language with names but no primary
therefore shows English, so a Malay reader saw an English name while Malay
names sat unused in the same table.

Which name is primary is decided upstream in the migration workspace, where the
rules and their reasoning live together; this applies that decision. Additive
for names - missing ones are created, existing ones matched case-insensitively
on (name, language) and never duplicated. Deleting a name ECHOcommunity no
longer lists is an editorial act, not a migration one.

Rehearsed against staging: 57 names created, 1741 already present, 546 primary
flags set, 16 cleared, 0 failures. Primary coverage went from 1 of 186 Thai
names to 207 of 245, Spanish 53 to 107, French 40 to 74.

Full suite 2310 examples, 0 failures. Whole-repo rubocop clean.
Names match case-insensitively, so 'Velvet Bean' and 'velvet bean' are the same
name. ECHOcommunity's casing is the curated one, and leaving the API holding a
variant meant the title sync pushed that variant back - 'Velvet Bean' became
'velvet bean' on the public site.

Full suite 2311 examples, 0 failures. Whole-repo rubocop clean.
@npflood
npflood merged commit dd5fafe into master Aug 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant