Skip to content

Reconcile seeded FormBuilders by id and prune duplicates#1571

Merged
maebeale merged 1 commit into
mainfrom
maebeale/seed-formbuilder-reconcile
Jun 6, 2026
Merged

Reconcile seeded FormBuilders by id and prune duplicates#1571
maebeale merged 1 commit into
mainfrom
maebeale/seed-formbuilder-reconcile

Conversation

@maebeale

@maebeale maebeale commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

What is the goal of this PR and why is this important?

  • The canonical FormBuilder records are referenced by fixed id elsewhere in the app, but the seed created them keyed on name + windows_type.
  • When a WindowsType was 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?

  • Key the seed on the fixed id and reconcile name + windows_type on every run, so reseeding is idempotent and survives WindowsType records being recreated.
  • Prune exact-name duplicates that fall outside the pinned ids and own no forms — so form-bearing records (production builders are seeded via migrations and own forms) are never touched.

Anything else to add?

  • Split out from the event-dashboard work; touches only db/seeds.rb.

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>
Copilot AI review requested due to automatic review settings June 6, 2026 18:01
@maebeale maebeale marked this pull request as ready for review June 6, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 FormBuilder records by fixed id, reconciling name and windows_type on each seed run.
  • Add a duplicate-pruning pass for exact-name duplicates outside the pinned IDs.

Comment thread db/seeds.rb
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? }
@maebeale maebeale merged commit 1e05e35 into main Jun 6, 2026
4 checks passed
@maebeale maebeale deleted the maebeale/seed-formbuilder-reconcile branch June 6, 2026 18:14
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.

2 participants