Schema plus

1,741 views

Published on

SchemaPlus gem - ActiveRecord enhanced capabilities for querying and defining database schemas

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,741
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Schema plus

  1. 1. SchemaPlusenhanced capabilities for schema definition and querying Ronen Barzel & Michał Łomnicki
  2. 2. HistorySimon Harris / harukizaemonredhillonrails_core (2006, 2009)foreign_key_migrations => automatic_foreign_keyschema_plus (2011)
  3. 3. Goalssolid basewell-testedwell-documentedbetter name :)
  4. 4. Plain ActiveRecordcreate_table :comments do |t| t.text :body t.integer :post_id t.integer :author_idendexecute "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
  5. 5. With schema_pluscreate_table :comments do |t| t.text :body t.integer :post_id, :index => true t.integer :author_id, :references => :usersend
  6. 6. auto-index foreign keys# without auto_indext.integer :post_id, :index => true# with auto_indext.integer :post_id
  7. 7. indext.string :area_codet.string :local_number, :index => { :unique => true, :with => :area_code }
  8. 8. Other featuresglobal, per table and per statement configexpressional indexesviews
  9. 9. SchemaAssociations# without schema_associationsclass Post < ActiveRecord::Base belongs_to :author has_many :commentsend
  10. 10. SchemaAssociations# without schema_associationsclass Post < ActiveRecord::Base # associations auto-created from foreign keysend
  11. 11. SchemaValidationscreate_table :posts do |t| t.integer :author_id, :null => false, :references => :users t.integer :likes_count t.string :content, :limit => 5_000end
  12. 12. SchemaValidations# without schema_validationsclass Post < ActiveRecord::Base validates :author, :presence => true validates :likes_count, :numericality => true validates :content, :length => { :maximum => 5_000 }end
  13. 13. SchemaValidations# with schema_validationsclass Post < ActiveRecord::Baseend
  14. 14. Schema FamilyScary?...but thats next step for active record pattern
  15. 15. Questionshttp://github.com/lomba

×