Skip to content

Makes db/seeds.rb task idempotent - #5669

Merged
awwaiid merged 2 commits into
mainfrom
fix-db-seeds
Aug 28, 2026
Merged

awwaiid merged 2 commits into
mainfrom
fix-db-seeds

Conversation

@armahillo

@armahillo armahillo commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Encountered an angry error when I attempted to run the seeds task after it had already been done.

As a user
when I run bin/rails db:seed for the first time
I see an invalid partner_key (duplicate key) error

ActiveRecord::RecordInvalid: Validation failed: Name has already been taken, Partner key has already been taken (ActiveRecord::RecordInvalid)

Part of this was moving the support methods from the db/seeds.rb to lib/seeds.rb. Originally I tried deleting it but the organization_spec uses one of the seed methods.

find_or_create_by was favored here to ensure we aren't replicating. I had it use attributes_for so that it's still effectively mimicking the old behavior.

🤖 Claude was used for the iterative work after I came up with an initial plan and proof of concept.

Encountered an angry error when I attempted to run the seeds task after it had already been done.

Part of this was pulling the lib/seeds.rb method (a solitary seed method) into the db/seeds.rb file to exist alongside the other creation methods.

find_or_create_by was favored here to ensure we aren't replicating. I had it use attributes_for so that it's still effectively mimicking the old behavior.

Claude was used for the iterative work after I came up with an initial plan and proof of concept.
Leaning into the separation into the module and moving the other supporting methods to this file.

@awwaiid awwaiid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified working!

@awwaiid
awwaiid merged commit 26ab9fb into main Aug 28, 2026
22 checks passed
@awwaiid
awwaiid deleted the fix-db-seeds branch August 28, 2026 17:45
cielf pushed a commit to cielf/human-essentials that referenced this pull request Aug 28, 2026
Resolves rubyforgood#5669

Does a trivial migration of all wiki content to the docs/wiki folder.

Additional work is required to actually update the content etc, this is just a preliminary pass to bring the wiki content over to source control.

🤖 I automated the migration in plan mode with Claude.
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