-
Notifications
You must be signed in to change notification settings - Fork 480
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
Feedback: require script_level_id, and other similar db validations #30122
Conversation
I would recommend enforcing this via schema constraint at the DB layer instead: https://stackoverflow.com/questions/5966840/how-to-change-a-nullable-column-to-not-nullable-in-a-rails-migration Here is some rationale for this: https://thoughtbot.com/blog/validation-database-constraint-or-both
a missing script level seems to me like a programming error (not a thing a user can fix), so once you've added the schema constraint I don't think you'd need this model validation. |
Codecov Report
@@ Coverage Diff @@
## staging #30122 +/- ##
==========================================
Coverage ? 76.56%
==========================================
Files ? 674
Lines ? 27537
Branches ? 0
==========================================
Hits ? 21084
Misses ? 6453
Partials ? 0
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Erin! Looks good.
Thanks for the info @davidsbailey! I updated based on your suggestions. |
Ah, good questions! For the same reasons, it seems like the validations on level_id, student_id and teacher_id would all be better as schema constraints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to Dave's suggestion that this column (and the others you mentioned) should be enforced at the schema/database level. However, I think we should also have validations at the model level because those allow Rails to provide human-readable error messages when model constraints aren't met (more info from the Thoughtbot article Dave shared). Otherwise, the user (or, more likely, Honeybadger) would get the error from the database, which is less user-friendly.
Keeping these validations sounds fine to me! Good point about HB error readability, Maddie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 yay, thank you for adding these validations!
I learned that we don't want to enforce |
LP - 638
After backfilling all of the empty
script_level_id
fields for teacher feedbacks on production, staging, test and levelbuilder, it's time to makescript_level_id
a required field.For production, where accuracy matters more, I used a series of strategies to backfill
script_level_id
(#29900, #29822, #29753, #29711, #29701, #29676).There weren't any teacher feedbacks without a
script_level_id
on staging. And for test and levelbuilder I ran:TeacherFeedback.where(script_level_id: nil).each do |fb| fb.update_attributes(script_level_id: fb.level.script_levels[0].id) end
to select the first ScriptLevel associated with the saved Level.