-
Notifications
You must be signed in to change notification settings - Fork 19
Migrate Material authors and contributors from string array to has_many Person relationship #1173
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
base: master
Are you sure you want to change the base?
Conversation
|
@copilot Change the new |
Refactored in 4dcfbb4. Changed |
|
@copilot We have legacy clients who will be creating |
Implemented in 6afdfcf. Added a custom
Single-name strings (e.g., "Madonna") are stored with an empty first_name and the name as last_name. |
|
@copilot Do the same for |
Implemented in 83487c0. Created a include HasPeople
has_person_role :authors, role_key: 'author'
has_person_role :contributors, role_key: 'contributor'This creates both the scoped association and a custom setter for each role, accepting strings (legacy), hashes, or Person objects. Contributors now work identically to authors. |
|
@copilot The data migration that splits a legacy string author name into Instead of doing this, lets add a Additionally, change:
|
Implemented in 044c720 and dddb034. Added a
The |
|
@copilot Add an optional |
Implemented in ea22c13. Added an optional |
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
…y_name Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
… compatibility Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
ea22c13 to
8125c8b
Compare
|
TODO
|
Summary of changes
Material.authorsandMaterial.contributorsfrom string arrays to properhas_manyrelationships with a new genericPersonmodel containinggiven_name,family_name,full_name, andorcidfieldsHasPeopleconcern with ahas_person_rolemacro for DRY code that can be applied to any model and rolePersonLinkjoin table with arolefield, enabling reuse for different person roles (authors, contributors, etc.)peopleandperson_linkstables, migrate existing data preserving full names, and remove the legacy columns_person_form.html.erbpartial that accepts a role parameter for reusabilityfull_namewithout parsingauthors=andcontributors=setters for backwards compatibility with legacy API clients (accepts both old and new field names)belongs_to :profileassociation to Person model with automatic linking based on matching ORCIDMotivation and context
Enables proper author and contributor attribution with separate name fields and ORCID support for scholarly identification. The string arrays were limiting metadata quality and prevented linking to external author identifiers. The generic
Personmodel, polymorphicPersonLinkjoin table, andHasPeopleconcern allow for easy migration of any person-related fields on any model to the same structure. The automatic Profile linking via ORCID enables seamless integration between Person records and existing user profiles.Key Implementation Details
HasPeople Concern
Model Structure
Person Model Fields
full_name- The complete name as it should be displayed (preferred for legacy data migration)given_name- First/given name (optional if full_name is present)family_name- Last/family name (optional if full_name is present)orcid- ORCID identifier (optional)profile_id- Optional link to a Profile (auto-populated based on matching ORCID)Person-Profile Auto-Linking
When a Person is saved with an ORCID, it automatically links to a Profile with a matching ORCID:
The ORCID matching handles both full URL format (
https://orcid.org/...) and short ID format.Legacy API Support
Custom setters for both
authors=andcontributors=accept multiple formats for backwards compatibility:["John Doe", "Jane Smith"]- stored directly asfull_name[{given_name: "John", family_name: "Doe", orcid: "..."}]or[{full_name: "Dr. Jane Marie Smith"}]Legacy field names (
first_name,last_name) are also accepted and mapped togiven_name/family_name.UI Changes
API Response Format
{ "authors": [ { "id": 1, "given_name": "Jane", "family_name": "Smith", "full_name": "Dr. Jane Marie Smith", "name": "Dr. Jane Marie Smith", "orcid": "0000-0002-1234-5678", "profile_id": 42 } ], "contributors": [ { "id": 2, "given_name": "John", "family_name": "Doe", "full_name": "John Doe", "name": "John Doe", "orcid": "0000-0001-2345-6789", "profile_id": null } ] }Bioschemas Enhancement
{ "@type": "Person", "name": "Dr. Jane Marie Smith", "givenName": "Jane", "familyName": "Smith", "@id": "https://orcid.org/0000-0002-1234-5678" }Screenshots
N/A - Backend data model migration
Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.