Skip to content

Add plants:import_categories for the ECHOcommunity plant migration - #119

Merged
npflood merged 1 commit into
masterfrom
phase1/import-categories
Aug 13, 2026
Merged

Add plants:import_categories for the ECHOcommunity plant migration#119
npflood merged 1 commit into
masterfrom
phase1/import-categories

Conversation

@npflood

@npflood npflood commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Phase 1 of the plant-data ownership migration. Companion to #117 and #118, but
independent of both — merge in any order.

Creates missing plant categories and syncs membership from ECHOcommunity.

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

Categories share the UUID convention: ECHOcommunity's Resource id for a category
is this application's categories.id. That holds for all 14 categories the
two systems have in common, so no mapping table is needed.

Membership is not cosmetic. The GMCC selector gates on category membership,
so a plant that loses its links disappears from that tool entirely.

Behaviour worth reviewing

  • Additive. Existing links are kept and missing ones added; removing a link
    is an editorial act, not a migration one.
  • Categories are built then saved, not created — name is a required
    translated attribute, so create! validates before apply_translations has a
    chance to set it. That was a real failure, not a hypothetical one.
  • A dry run counts links for categories it is about to create. Otherwise it
    under-reports by the entire membership of every new category — 179 links for
    Bamboo alone — making the dry run look far smaller than the actual change.

Rehearsed against staging

Created the missing Bamboo category (182 ECHOcommunity plants; it postdates
the 2020 export) and 179 links, bringing categories to parity at 15 and links to
815.

The 8-link difference against ECHOcommunity's 823 is fully explained: 11 of
its rows point at plants that do not exist
— orphans in a join table that has
no primary key, no index and no foreign keys. They are unmigratable by
definition, so 812 is the correct number to carry across.

  • 6 new specs
  • Full suite: 2,310 examples, 0 failures
  • Rubocop clean

Creates missing plant categories and syncs membership. Categories share the
UUID convention: ECHOcommunity's Resource id for a category IS this
application's categories.id, which holds for all 14 categories the two systems
have in common, so no mapping table is needed.

Membership is not cosmetic - the GMCC selector gates on it, so a plant that
loses its category links disappears from that tool.

Additive by design: existing links are kept and missing ones added. Removing a
link is an editorial act, not a migration one.

Two details worth noting:

  - Categories are built then saved rather than created, because name is a
    required translated attribute and create! validates before the translation
    can be applied.
  - A dry run counts links belonging to categories it is about to create.
    Otherwise it under-reports by the entire membership of every new category -
    179 links for Bamboo alone, which made a dry run look far smaller than the
    real change.

Rehearsed against staging: created the missing Bamboo category and 179 links,
bringing categories to parity at 15 and links to 815. The 8-link difference
against ECHOcommunity's 823 is explained - 11 of its rows point at plants that
do not exist, orphans in a join table with no foreign keys.

Full suite 2319 examples, 0 failures. Rubocop clean.
@npflood
npflood force-pushed the phase1/import-categories branch from ce5fee7 to 1d38a5f Compare August 13, 2026 15:24
@npflood

npflood commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto master to clear a conflict in .rubocop.yml.

#117 and this PR each add a line to the same Metrics/BlockLength exclude list — plant_import.rake and plant_categories.rake — so once #117 merged, git saw competing edits on adjacent lines. Both belong; the resolution keeps them.

Re-verified against merged master: 2,353 examples, 0 failures, whole-repo rubocop clean across 744 files.

@npflood
npflood merged commit 77890b2 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