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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
AI & Enginnering
codelynx
0
110
AI 駆動開発ライフサイクル(AI-DLC):ソフトウェアエンジニアリングの再構築 / AI-DLC Introduction
kanamasa
12
6.5k
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
3
270
Vibe codingでおすすめの言語と開発手法
uyuki234
0
220
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
190
CSC307 Lecture 07
javiergs
PRO
0
550
今から始めるClaude Code超入門
448jp
7
8.3k
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
120
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
250
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
432
66k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
110
Balancing Empowerment & Direction
lara
5
880
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
90
Exploring anti-patterns in Rails
aemeredith
2
250
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
290
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
320
Making Projects Easy
brettharned
120
6.6k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
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]