diff options
author | danielgrippi <danielgrippi@gmail.com> | 2011-07-09 07:01:07 +0400 |
---|---|---|
committer | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-12 02:05:55 +0400 |
commit | d364f158b8c08700a468b3fd28bbc1169a70bb67 (patch) | |
tree | 0bd32789ca74b6f9d5cac38d4eef190131dfa083 /db | |
parent | e0bbde4ce2ba16d8a8dab0787803f8178e2126f4 (diff) |
cache counters in for likes. pending Diaspora::Likeable module...
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20110707234802_likes_on_comments.rb | 13 | ||||
-rw-r--r-- | db/schema.rb | 16 |
2 files changed, 18 insertions, 11 deletions
diff --git a/db/migrate/20110707234802_likes_on_comments.rb b/db/migrate/20110707234802_likes_on_comments.rb index 2df5e02c5..3438c4a9b 100644 --- a/db/migrate/20110707234802_likes_on_comments.rb +++ b/db/migrate/20110707234802_likes_on_comments.rb @@ -1,19 +1,26 @@ class LikesOnComments < ActiveRecord::Migration def self.up + remove_foreign_key :likes, :posts + add_column :likes, :target_type, :string, :null => false - add_column :likes, :target_id, :integer, :null => false - remove_column :posts, :likes_count + rename_column :likes, :post_id, :target_id + + add_column :comments, :likes_count, :integer, :default => 0, :null => false execute <<SQL UPDATE likes SET target_type = 'Post' SQL + + add_index :likes, [:target_id, :target_type], :unique => true end def self.down - add_column :posts, :likes_count, :integer + remove_column :comments, :likes_count + remove_column :likes, :target_type rename_column :likes, :target_id, :post_id add_index :likes, :post_id + remove_index :likes, :target_id end end diff --git a/db/schema.rb b/db/schema.rb index e05d2feb8..6ca59081c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -46,15 +46,16 @@ ActiveRecord::Schema.define(:version => 20110707234802) do add_index "aspects", ["user_id"], :name => "index_aspects_on_user_id" create_table "comments", :force => true do |t| - t.text "text", :null => false - t.integer "post_id", :null => false - t.integer "author_id", :null => false - t.string "guid", :null => false + t.text "text", :null => false + t.integer "post_id", :null => false + t.integer "author_id", :null => false + t.string "guid", :null => false t.text "author_signature" t.text "parent_author_signature" t.text "youtube_titles" t.datetime "created_at" t.datetime "updated_at" + t.integer "likes_count", :default => 0, :null => false end add_index "comments", ["author_id"], :name => "index_comments_on_person_id" @@ -110,7 +111,7 @@ ActiveRecord::Schema.define(:version => 20110707234802) do create_table "likes", :force => true do |t| t.boolean "positive", :default => true - t.integer "post_id" + t.integer "target_id" t.integer "author_id" t.string "guid" t.text "author_signature" @@ -118,12 +119,11 @@ ActiveRecord::Schema.define(:version => 20110707234802) do t.datetime "created_at" t.datetime "updated_at" t.string "target_type", :null => false - t.integer "target_id", :null => false end add_index "likes", ["author_id"], :name => "likes_author_id_fk" add_index "likes", ["guid"], :name => "index_likes_on_guid", :unique => true - add_index "likes", ["post_id"], :name => "index_likes_on_post_id" + add_index "likes", ["target_id"], :name => "index_likes_on_post_id" create_table "mentions", :force => true do |t| t.integer "post_id", :null => false @@ -268,6 +268,7 @@ ActiveRecord::Schema.define(:version => 20110707234802) do t.string "actor_url" t.integer "objectId" t.string "status_message_guid" + t.integer "likes_count", :default => 0 end add_index "posts", ["author_id"], :name => "index_posts_on_person_id" @@ -419,7 +420,6 @@ ActiveRecord::Schema.define(:version => 20110707234802) do add_foreign_key "invitations", "users", :name => "invitations_sender_id_fk", :column => "sender_id", :dependent => :delete add_foreign_key "likes", "people", :name => "likes_author_id_fk", :column => "author_id", :dependent => :delete - add_foreign_key "likes", "posts", :name => "likes_post_id_fk", :dependent => :delete add_foreign_key "messages", "conversations", :name => "messages_conversation_id_fk", :dependent => :delete add_foreign_key "messages", "people", :name => "messages_author_id_fk", :column => "author_id", :dependent => :delete |