Migrate sector taggings onto the canonical sector list#1756
Open
maebeale wants to merge 1 commit into
Open
Conversation
PR #1703 refreshed SECTOR_TYPES and seeded the new names but left existing taggings stranded on the unpublished legacy sectors. This task re-homes those taggings — renaming legacy sectors in place where the canonical name does not yet exist, or merging into it via ModelDeduper where it does — so the new published sectors carry the real workshop/story/etc. taggings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
maebeale
commented
Jun 18, 2026
| # The target name is already taken by a different record, so an in-place | ||
| # rename would violate the uniqueness validation. Fall back to a merge. | ||
| puts " COLLISION #{from.inspect} -> #{to.inspect}: target ##{existing_target.id} exists, merging instead" | ||
| merges << [ from, to ] |
Collaborator
Author
There was a problem hiding this comment.
🤖 From Claude: This collision branch is what makes the task deploy-order-agnostic: once #1703 seeds have created the new canonical name, an in-place rename would violate the uniqueness validation, so we route it through a merge onto the already-seeded published record instead.
maebeale
commented
Jun 18, 2026
| target = find_by_name.call(target_name) | ||
| # In a dry run the prerequisite rename hasn't been persisted, so resolve | ||
| # the target back through its pre-rename name to preview accurately. | ||
| target ||= find_by_name.call(renames.key(target_name)) |
Collaborator
Author
There was a problem hiding this comment.
🤖 From Claude: Dry-run only: the prerequisite rename (e.g. Education/Schools → Education) is not persisted in a dry run, so the merge target wont be found by its new name. Resolving back through renames.key lets the dry run preview the Student → Education merge accurately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the goal of this PR and why is this important?
Sector::SECTOR_TYPESto the new canonical service-area list, seeded descriptions, and made seeds create the new names while unpublishing (not destroying) the legacy ones.Child Abuse,Criminal/Legal,Student), while the new published sectors (Child Abuse/Neglect,Court/Legal System,Education) are empty.How did you approach the change?
lib/tasks/consolidate_sectors.rake(data:consolidate_sectors), dry-run by default;DRY_RUN=falseto apply.Criminal/Legal → Court/Legal System): in-placeupdate!, which keeps the same row and all its taggings — nothing is removed.ModelDeduper) only when two rows must collapse into one:StudentandEducation/Schoolsboth map toEducation— a genuine 2:1 merge.Student's taggings folded intoEducationwith no loss, second run skipped all steps. Rubocop clean.Anything else to add?
sectorsrow (rename); only a genuine 2:1 merge removes a now-empty redundant row, which is the standard behavior of the existingModelDeduperdedupe code.🤖 Generated with Claude Code