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
500
Service-Oriented Architecture
barunio
2
170
Other Decks in Programming
See All in Programming
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
110
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.3k
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
0
230
ALB ログから Trace を気合で繋げる技術
fohte
7
870
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
130
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
500
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
53
35k
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
580
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
280
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.8k
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
310
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.8k
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
520
How STYLIGHT went responsive
nonsquared
100
6.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Visualization
eitanlees
152
17k
Typedesign – Prime Four
hannesfritz
42
3.2k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
530
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Faster Mobile Websites
deanohume
310
32k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
How to train your dragon (web standard)
notwaldorf
97
6.8k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
320
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]