Add source_field to the enrichments model#1494
Conversation
📝 WalkthroughWalkthroughThis pull request introduces a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
app/models/enrichment.rb (1)
5-6: Validatesource_idagainst the column limit.
source_idis now required, but the model still allows values longer than the 255-byte column. That won't fail untilsave, which can turn an input mistake into a DB error instead of a normal validation failure.Proposed fix
- validates :uuid, presence: true, uniqueness: true - validates :source_id, presence: true + validates :uuid, presence: true, uniqueness: true + validates :source_id, presence: true, length: { maximum: 255 }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/models/enrichment.rb` around lines 5 - 6, The model Enrichment validates presence of :source_id but not its maximum length, which can allow values exceeding the 255-byte DB column; add a length validation to the model (e.g., update the validates for :source_id in Enrichment to include length: { maximum: 255 } or implement a custom validator that checks source_id.bytesize <= 255) so invalid inputs fail model validation instead of raising a DB error on save.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/jobs/enrichment_batch_process_job.rb`:
- Line 8: The perform method signature change breaks already-enqueued jobs;
update the perform definition in enrichment_batch_process_job.rb (the perform
method) to give source_id a safe default (e.g., def perform(lines, filename,
source_id = nil)) so older jobs without the third arg won't raise ArgumentError,
and ensure any downstream code inside perform handles a nil/absent source_id
appropriately.
In `@db/migrate/20260310084109_add_source_id_to_enrichments.rb`:
- Around line 4-6: The migration currently calls add_column :enrichments,
:source_id, :string, limit: 255, null: false which will fail if enrichments
already contains rows; change this to a safe two-step pattern: first add_column
:enrichments, :source_id, :string, limit: 255, null: true (or in a separate
migration create the column nullable), then backfill existing rows (e.g.
Enrichment.reset_column_information; Enrichment.where(source_id:
nil).update_all(source_id: '<appropriate value>' or computed values)), and
finally run change_column_null :enrichments, :source_id, false (and optionally
add an index) in a follow-up migration to enforce NOT NULL.
---
Nitpick comments:
In `@app/models/enrichment.rb`:
- Around line 5-6: The model Enrichment validates presence of :source_id but not
its maximum length, which can allow values exceeding the 255-byte DB column; add
a length validation to the model (e.g., update the validates for :source_id in
Enrichment to include length: { maximum: 255 } or implement a custom validator
that checks source_id.bytesize <= 255) so invalid inputs fail model validation
instead of raising a DB error on save.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2b9f3566-3c3e-4502-8e3d-70d7b4267889
📒 Files selected for processing (5)
app/jobs/enrichment_batch_process_job.rbapp/models/enrichment.rbdb/migrate/20260310084109_add_source_id_to_enrichments.rbdb/schema.rblib/tasks/enrichment.rake
Purpose
closes: https://github.com/datacite/product-backlog/issues/689
Approach
Open Questions and Pre-Merge TODOs
Learning
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Reviewer, please remember our guidelines:
Summary by CodeRabbit