Reconcile seeded FormBuilders by id and prune duplicates#1571
Merged
Conversation
The canonical FormBuilders are referenced by fixed id elsewhere in the app, but the seed created them keyed on name+windows_type. When a WindowsType was renamed/recreated, reseeding spawned duplicate builders at fresh ids. Key the seed on the fixed id and reconcile name + windows_type on every run, then prune exact-name duplicates outside the pinned ids that own no forms — so reseeding is idempotent and form-bearing records are never touched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Makes FormBuilder seeding idempotent by keying canonical builders on fixed IDs (so app code that references specific IDs stays correct across reseeds) and adds cleanup logic intended to remove legacy duplicates created by older seed behavior.
Changes:
- Seed canonical
FormBuilderrecords by fixedid, reconcilingnameandwindows_typeon each seed run. - Add a duplicate-pruning pass for exact-name duplicates outside the pinned IDs.
Comment on lines
+296
to
+298
| FormBuilder.where(name: form_builders.values.map(&:first)) | ||
| .where.not(id: form_builders.keys) | ||
| .each { |duplicate| duplicate.destroy! if duplicate.forms.empty? } |
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?
FormBuilderrecords are referenced by fixed id elsewhere in the app, but the seed created them keyed onname+windows_type.WindowsTypewas renamed or recreated, reseeding spawned duplicate builders at fresh auto-increment ids, drifting away from the ids the app expects.How did you approach the change?
name+windows_typeon every run, so reseeding is idempotent and survivesWindowsTyperecords being recreated.Anything else to add?
db/seeds.rb.