Data Integrity: Null Constraints and Check Constraints

Episode #6 in the Inside The Muse Series

by Jack Kinsella

@semicolonandson

Data is more important than code, therefore the most important job you, as a programmer, have is to design a system that allows for a simple, constrained, and predictable set of data. In this episode, I'll discuss how null constraints can reduce the number of types your program has to deal with, thereby simplifying your code. Then I discuss how check constraints can force data to take a limited (and more useful) range of values. Lastly I'll explain why it's better to carry all this out at the database level rather than at the Ruby/Python/Php/JS level.

Show Notes

References

Postgresql Documentation on Constraints - covers check constraints, not null constraints, and more. Are email addresses case sensitive - technically the part before the "@" in an email can be case sensitive, but in practice it almost never is. The &. operator you saw - Ruby's safe navigation operator (&.)

Rails stuff

Attribute Normalizer gem - what I use at the Rails level to remove trailing/leading whitespaces before saving records Lifecyle methods - how Rails allows you to hook in behavior when a record is created, saved, etc.

Want To Become A Stronger Programmer?

Our screencasts are aimed at intermediate and advanced programmers and focus on:

  • Timeless technologies like unix, vim, SQL, program design, software testing etc. (so your learning lasts 30 years instead of 30 months)
  • Production codebases (instead of toy examples)
  • Softer skills (especially online marketing) necessary to flourish as a financially independent software developer
  • Mailing list members receive exclusive content as well as episode alerts. Never spam.