Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Using Database Constraints Wisely
Search
Barun Singh
December 13, 2011
Programming
130
1
Share
Using Database Constraints Wisely
Barun Singh
December 13, 2011
More Decks by Barun Singh
See All by Barun Singh
Atomic Commits
barunio
1
480
Service-Oriented Architecture
barunio
2
160
Other Decks in Programming
See All in Programming
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
2k
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
490
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
360
【ディップ|26年新卒研修資料】TDD実装演習
dip_tech
PRO
0
190
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
150
20260514_its_the_context_window_stupid.pdf
heita
0
1k
関係性から理解する"同一性"の型用語たち
pvcresin
1
130
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
160
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
3
940
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
770
GoogleCloudとterraform完全に理解した
terisuke
1
200
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
3.1k
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
120
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
810
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
250
The Invisible Side of Design
smashingmag
302
52k
We Have a Design System, Now What?
morganepeng
55
8.1k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
460
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
Transcript
Using database constraints wisely Barun Singh
[email protected]
Founder & CTO
What is a database? A collection of data that you
can read, write, and organize The software tools that let you do this
What do we want from a database? It should be
… • Reliable • Fast • Secure • …
A relational database is not the same as a generic
data store
A relational database is not the same as a generic
data store
What do we want from a relational database? It should
be … • Reliable • Fast • Secure • Sensible • …
Wait a minute… Is this Rails approved™ ?
The Rails way says… • You should be database agnostic
• Application layer is the only really important part
The database is important
But why? Because you make mistakes.
What’s the worst that can happen? • Feature doesn’t work
• Site goes down • Irrecoverable data loss
I write tests. Why bother with database constraints? I test
my entire application flow through integration tests. Why write unit tests?
I write tests. Why bother with database constraints? My application
requires Javascript, and I have JS validations. Why bother with model-level validations?
Your database has an interface.
How? • Simple constraints: [not null] • Unique indices •
Foreign keys [foreigner gem]
It’s not always that simple
Polymorphism Imageable Picture Employee Product
Polymorphism What does this reference?
Polymorphism
Polymorpheus
A couple little snags… How can you make sure that
one picture has only an employee_id or product_id but not both? (xor constraints are tough) And what if the polymorphic relationship has to be unique?
Polymorpheus The gem takes care of all of this for
you through a simple migration method
Polymorpheus The gem takes care of all of this for
you through a simple migration method
Polymorpheus
Polymorpheus Also provides a validation method, model level validations are
still important
You can keep your application logic clean and set up
your database properly
Questions?
[email protected]