Your SlideShare is downloading. ×
0
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Schema plus
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Schema plus

1,469

Published on

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

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,469
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×