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
FDEが実現するAI駆動経営の現在地
gonta
2
280
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
170
プロポーザルを書いてもらう
pvcresin
0
300
React本体のコードリーディング
high_g_engineer
1
140
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
540
5分で問診!Composer セキュリティ健康診断
codmoninc
0
920
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
数百円から始めるRuby電子工作
tarosay
0
140
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
170
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
2
1.8k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
430
How to Talk to Developers About Accessibility
jct
2
500
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.5k
Fireside Chat
paigeccino
42
4k
My Coaching Mixtape
mlcsv
0
210
Building an army of robots
kneath
306
46k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Code Reviewing Like a Champion
maltzj
528
40k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.3k
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]