SlideShare a Scribd company logo
SchemaPlus
enhanced capabilities for schema definition and querying
          Ronen Barzel & Michał Łomnicki
History
Simon Harris / harukizaemon

redhillonrails_core (2006, 2009)

foreign_key_migrations => automatic_foreign_key

schema_plus (2011)
Goals
solid base

well-tested

well-documented

better name :)
Plain ActiveRecord
create_table :comments do |t|
    t.text :body
    t.integer :post_id
    t.integer :author_id
end
execute "ALTER TABLE comments ADD FOREIGN KEY (post_id) 
    REFERENCES (posts)"
execute "ALTER TABLE comments ADD FOREIGN KEY (author_id) 
    REFERENCES (users)"
add_index :comments, :post_id
With schema_plus
create_table :comments do |t|
    t.text :body
    t.integer :post_id, :index => true
    t.integer :author_id, :references => :users
end
auto-index foreign keys
# without auto_index
t.integer :post_id, :index => true
# with auto_index
t.integer :post_id
index
t.string :area_code
t.string :local_number,
     :index => { :unique => true, :with => :area_code }
Other features
global, per table and per statement config

expressional indexes

views
SchemaAssociations
# without schema_associations
class Post < ActiveRecord::Base
    belongs_to :author
    has_many :comments
end
SchemaAssociations
# without schema_associations
class Post < ActiveRecord::Base
    # associations auto-created from foreign keys
end
SchemaValidations
create_table :posts do |t|
    t.integer :author_id, :null => false, :references => :users
    t.integer :likes_count
    t.string :content, :limit => 5_000
end
SchemaValidations
# without schema_validations
class Post < ActiveRecord::Base
    validates :author, :presence => true
    validates :likes_count, :numericality => true
    validates :content, :length => { :maximum => 5_000 }
end
SchemaValidations
# with schema_validations
class Post < ActiveRecord::Base
end
Schema Family
Scary?

...but that's next step for active record pattern
Questions
http://github.com/lomba

More Related Content

PDF
Vizwik Coding Manual
PDF
Vizwik part 2 scripts
PPT
Xhtml Part2
PPTX
ODP
Database index by Reema Gajjar
DOCX
Asp controls
PPTX
Database index
PPTX
Sweeping out the cobwebs: Content auditing for large websites
Vizwik Coding Manual
Vizwik part 2 scripts
Xhtml Part2
Database index by Reema Gajjar
Asp controls
Database index
Sweeping out the cobwebs: Content auditing for large websites

Viewers also liked (7)

PDF
ACID - Transakcje
PDF
Nodejs + Rails
PDF
Having fun with legacy apps
PDF
Ruby tricks2
PDF
DDD, Rails and persistence
PDF
Cap Theorem
PPTX
Tradycyjne indeksy w sql server
ACID - Transakcje
Nodejs + Rails
Having fun with legacy apps
Ruby tricks2
DDD, Rails and persistence
Cap Theorem
Tradycyjne indeksy w sql server
Ad

Similar to Schema plus (20)

PDF
Data Integrity in Rails
PDF
Where's My SQL? Designing Databases with ActiveRecord Migrations
PDF
Introduction to Active Record at MySQL Conference 2007
ZIP
Rails and alternative ORMs
PDF
Introduction to Active Record - Silicon Valley Ruby Conference 2007
KEY
Schema Design (Mongo Austin)
PDF
A farewell to ORMs
PDF
ActiveRecord Query Interface (2), Season 2
PDF
Schema Design
KEY
MongoDB at RubyEnRails 2009
PPTX
Active record(1)
KEY
Rails and Legacy Databases - RailsConf 2009
PDF
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
PDF
DataMapper
PDF
Intro to MongoDB and datamodeling
PDF
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
KEY
Active Record Query Interface (2), Season 1
KEY
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
PDF
Advanced O/R Mapping with Glorp
KEY
Practical Ruby Projects With Mongo Db
Data Integrity in Rails
Where's My SQL? Designing Databases with ActiveRecord Migrations
Introduction to Active Record at MySQL Conference 2007
Rails and alternative ORMs
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Schema Design (Mongo Austin)
A farewell to ORMs
ActiveRecord Query Interface (2), Season 2
Schema Design
MongoDB at RubyEnRails 2009
Active record(1)
Rails and Legacy Databases - RailsConf 2009
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
DataMapper
Intro to MongoDB and datamodeling
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
Active Record Query Interface (2), Season 1
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Advanced O/R Mapping with Glorp
Practical Ruby Projects With Mongo Db
Ad

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Machine learning based COVID-19 study performance prediction
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
sap open course for s4hana steps from ECC to s4
The Rise and Fall of 3GPP – Time for a Sabbatical?

Schema plus