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

Don't use first_or_create to merge seed data with existing dataset #18431

Merged
merged 2 commits into from Oct 17, 2017

Conversation

jopolsky
Copy link

@jopolsky jopolsky commented Oct 17, 2017

** Execute seed:school_districts
seeding school districts (19059 rows)
rake aborted!
ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry '100021' for key 'PRIMARY': INSERT INTO `school_districts` (`id`, `name`, `city`, `state`, `zip`, `created_at`, `updated_at`) VALUES (100021, 'BREWERS PORCH CHILDRENS CENTER', 'TUSCALOOSA', 'AL', '35487', '2017-10-17 15:30:27', '2017-10-17 15:30:27')

Seeding calls find_or_create_all_from_tsv which was executing SchoolDistrict.where(attributes).first_or_create! on the model. This doesn't support the case where existing data has changed. For instance, a school district entry in the TSV file where the city name has changed.

I created a new method for #18396 which merges the results. This change forwards the find_or_create_all_from_tsv call to the new merge_from_csv.

@jopolsky jopolsky requested a review from wjordan October 17, 2017 15:16
@jopolsky jopolsky force-pushed the symbolize-keys-when-seeding-school-data branch from da9e22f to cd07f74 Compare October 17, 2017 16:09
@jopolsky jopolsky changed the title Ensure symbolize_keys when seeding schools data [ci skip] Don't muse first_or_create to merge seed data [ci skip] Oct 17, 2017
@jopolsky jopolsky changed the title Don't muse first_or_create to merge seed data [ci skip] Don't muse first_or_create to merge seed data with existing dataset [ci skip] Oct 17, 2017
@jopolsky jopolsky changed the title Don't muse first_or_create to merge seed data with existing dataset [ci skip] Don't use first_or_create to merge seed data with existing dataset Oct 17, 2017
Copy link
Contributor

@wjordan wjordan left a comment

Choose a reason for hiding this comment

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

LGTM, given that you ran these changes locally and merges the results properly.

@jopolsky jopolsky merged commit cda8a83 into staging Oct 17, 2017
@jopolsky jopolsky deleted the symbolize-keys-when-seeding-school-data branch October 17, 2017 17:11
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.

None yet

2 participants