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
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Using Database Constraints Wisely
Barun Singh
December 13, 2011
More Decks by Barun Singh
See All by Barun Singh
Atomic Commits
barunio
1
490
Service-Oriented Architecture
barunio
2
170
Other Decks in Programming
See All in Programming
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
自作OSでスライド発表する
uyuki234
1
3.8k
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
0
200
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
640
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
220
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
170
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
330
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
110
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.2k
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.8k
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
900
Un-Boring Meetings
codingconduct
0
350
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
880
The Curse of the Amulet
leimatthew05
2
13k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
970
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
230
Prompt Engineering for Job Search
mfonobong
0
380
Unsuck your backbone
ammeep
672
58k
Code Reviewing Like a Champion
maltzj
528
40k
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]