SlideShare a Scribd company logo
Using database
constraints wisely
         Barun Singh
    bsingh@wegowise.com

       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
           Employee
Picture
           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?


bsingh@wegowise.com

More Related Content

Similar to Using Database Constraints Wisely

Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the CloudWebinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Internap
 
A Decade of SharePoint Adoption Strategies
A Decade of SharePoint Adoption StrategiesA Decade of SharePoint Adoption Strategies
A Decade of SharePoint Adoption Strategies
Chris McNulty
 
[EN] Club Automation presentation "Quality Model for Industrial Automation", ...
[EN] Club Automation presentation "Quality Model for Industrial Automation", ...[EN] Club Automation presentation "Quality Model for Industrial Automation", ...
[EN] Club Automation presentation "Quality Model for Industrial Automation", ...
Itris Automation Square
 
Getting Started with DevOps
Getting Started with DevOpsGetting Started with DevOps
Getting Started with DevOps
IBM UrbanCode Products
 
The Application Development Landscape - 2011
The Application Development Landscape -  2011The Application Development Landscape -  2011
The Application Development Landscape - 2011
David Skok
 
Getting started with Cloud Foundry
Getting started with Cloud FoundryGetting started with Cloud Foundry
Getting started with Cloud Foundry
Lode Vermeiren
 
Getting started with Cloud Foundry
Getting started with Cloud FoundryGetting started with Cloud Foundry
Getting started with Cloud Foundry
Lode Vermeiren
 
Final app presentation
Final app presentationFinal app presentation
Final app presentation
Murali Krishna
 
Bigdata Final NSF I-Corps Presentation
Bigdata Final NSF I-Corps PresentationBigdata Final NSF I-Corps Presentation
Bigdata Final NSF I-Corps Presentation
Stanford University
 
Location Analytics - Session Evaluation Results
Location Analytics  - Session Evaluation ResultsLocation Analytics  - Session Evaluation Results
Location Analytics - Session Evaluation Results
Jitender Aswani
 
SOA OSB BPEL BPM Presentation
SOA OSB BPEL BPM PresentationSOA OSB BPEL BPM Presentation
SOA OSB BPEL BPM Presentation
Liviu Claudiu Cismaru
 
Firefox3.5 And Next
Firefox3.5 And NextFirefox3.5 And Next
Firefox3.5 And Next
Channy Yun
 
Mobile Cloud Architectures
Mobile Cloud ArchitecturesMobile Cloud Architectures
Mobile Cloud Architectures
David Coallier
 
Intro to Table-Grouping™ technology
Intro to Table-Grouping™ technologyIntro to Table-Grouping™ technology
Intro to Table-Grouping™ technology
David McFarlane
 
Vineet Choudhry Portfolio
Vineet Choudhry PortfolioVineet Choudhry Portfolio
Vineet Choudhry Portfolio
Rakesh Ranjan
 
1112 agile approach to pci dss development
1112 agile approach to pci dss development1112 agile approach to pci dss development
1112 agile approach to pci dss development
bezpiecznik
 
From java to rails
From java to railsFrom java to rails
From java to rails
jokry
 
Navigating Your Career Roadmap, Detours and Rough Roads
Navigating Your Career Roadmap, Detours and Rough RoadsNavigating Your Career Roadmap, Detours and Rough Roads
Navigating Your Career Roadmap, Detours and Rough Roads
Jill Hurst-Wahl
 
OSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business ProcessesOSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business Processes
Eric D. Schabell
 
Mas overview dirks at cni dec11b
Mas overview dirks at cni   dec11bMas overview dirks at cni   dec11b
Mas overview dirks at cni dec11b
Lee Dirks
 

Similar to Using Database Constraints Wisely (20)

Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the CloudWebinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
 
A Decade of SharePoint Adoption Strategies
A Decade of SharePoint Adoption StrategiesA Decade of SharePoint Adoption Strategies
A Decade of SharePoint Adoption Strategies
 
[EN] Club Automation presentation "Quality Model for Industrial Automation", ...
[EN] Club Automation presentation "Quality Model for Industrial Automation", ...[EN] Club Automation presentation "Quality Model for Industrial Automation", ...
[EN] Club Automation presentation "Quality Model for Industrial Automation", ...
 
Getting Started with DevOps
Getting Started with DevOpsGetting Started with DevOps
Getting Started with DevOps
 
The Application Development Landscape - 2011
The Application Development Landscape -  2011The Application Development Landscape -  2011
The Application Development Landscape - 2011
 
Getting started with Cloud Foundry
Getting started with Cloud FoundryGetting started with Cloud Foundry
Getting started with Cloud Foundry
 
Getting started with Cloud Foundry
Getting started with Cloud FoundryGetting started with Cloud Foundry
Getting started with Cloud Foundry
 
Final app presentation
Final app presentationFinal app presentation
Final app presentation
 
Bigdata Final NSF I-Corps Presentation
Bigdata Final NSF I-Corps PresentationBigdata Final NSF I-Corps Presentation
Bigdata Final NSF I-Corps Presentation
 
Location Analytics - Session Evaluation Results
Location Analytics  - Session Evaluation ResultsLocation Analytics  - Session Evaluation Results
Location Analytics - Session Evaluation Results
 
SOA OSB BPEL BPM Presentation
SOA OSB BPEL BPM PresentationSOA OSB BPEL BPM Presentation
SOA OSB BPEL BPM Presentation
 
Firefox3.5 And Next
Firefox3.5 And NextFirefox3.5 And Next
Firefox3.5 And Next
 
Mobile Cloud Architectures
Mobile Cloud ArchitecturesMobile Cloud Architectures
Mobile Cloud Architectures
 
Intro to Table-Grouping™ technology
Intro to Table-Grouping™ technologyIntro to Table-Grouping™ technology
Intro to Table-Grouping™ technology
 
Vineet Choudhry Portfolio
Vineet Choudhry PortfolioVineet Choudhry Portfolio
Vineet Choudhry Portfolio
 
1112 agile approach to pci dss development
1112 agile approach to pci dss development1112 agile approach to pci dss development
1112 agile approach to pci dss development
 
From java to rails
From java to railsFrom java to rails
From java to rails
 
Navigating Your Career Roadmap, Detours and Rough Roads
Navigating Your Career Roadmap, Detours and Rough RoadsNavigating Your Career Roadmap, Detours and Rough Roads
Navigating Your Career Roadmap, Detours and Rough Roads
 
OSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business ProcessesOSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business Processes
 
Mas overview dirks at cni dec11b
Mas overview dirks at cni   dec11bMas overview dirks at cni   dec11b
Mas overview dirks at cni dec11b
 

Recently uploaded

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 

Recently uploaded (20)

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 

Using Database Constraints Wisely