Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure random record for organization in seeds #4212

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

veezus
Copy link
Contributor

@veezus veezus commented Mar 21, 2024

Resolves #4211.

Description

When seeding donations, we expect between one and five items attached to each donation (each with several hundred quantity). For some reason, the random_record_for_org method was caching, resulting up to five line items with the same item.

This PR just ensures that a fresh record is returned for each line item.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I've run and re-run the bin/setup process multiple times and ensured the data generated looks correct.

Screenshots

Before

Donations without modification

After

Donations with modification

@@ -19,7 +19,7 @@ def random_record(klass)
end

def random_record_for_org(org, klass)
klass.where(organization: org).limit(1).order(Arel.sql('random()')).first
klass.where(organization: org).all.sample
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we're in fresh-seeding territory and row counts are very low, we went with all.sample which is pretty foolproof.

@veezus veezus marked this pull request as ready for review March 21, 2024 17:23
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

This does seem to work much better. @dorner, do you have any objections?

@dorner dorner merged commit 9f3c93c into rubyforgood:main Mar 22, 2024
@veezus veezus deleted the donation-seeds branch March 22, 2024 19:06
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.

[Bug]Donations in seed are only getting 1 line item, though they should be getting 1 to 5
3 participants