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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Barun Singh
December 13, 2011
Programming
1
130
Using Database Constraints Wisely
Barun Singh
December 13, 2011
Tweet
Share
More Decks by Barun Singh
See All by Barun Singh
Atomic Commits
barunio
1
470
Service-Oriented Architecture
barunio
2
160
Other Decks in Programming
See All in Programming
CDIの誤解しがちな仕様とその対処TIPS
futokiyo
0
180
RubyとGoでゼロから作る証券システム: 高信頼性が求められるシステムのコードの外側にある設計と運用のリアル
free_world21
0
220
日本だけで解禁されているアプリ起動の方法
ryunakayama
0
370
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
490
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.1k
CSC307 Lecture 14
javiergs
PRO
0
450
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
360
AI活用のコスパを最大化する方法
ochtum
0
120
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
400
TROCCOで実現するkintone+BigQueryによるオペレーション改善
ssxota
0
140
CSC307 Lecture 12
javiergs
PRO
0
460
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.5k
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
280
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
The Language of Interfaces
destraynor
162
26k
Facilitating Awesome Meetings
lara
57
6.8k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
210
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
エンジニアに許された特別な時間の終わり
watany
106
240k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
Faster Mobile Websites
deanohume
310
31k
Test your architecture with Archunit
thirion
1
2.2k
How STYLIGHT went responsive
nonsquared
100
6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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]