From 38d685e06e0a0a2c90c5ee88cdf5adc5b548618c Mon Sep 17 00:00:00 2001
From: danielgrippi <danielgrippi@gmail.com>
Date: Mon, 17 Oct 2011 18:19:02 -0700
Subject: [PATCH] add proper index to comments

---
 db/migrate/20111018010003_add_back_indexes.rb | 18 ++++++++++++++++++
 db/schema.rb                                  |  5 ++++-
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 db/migrate/20111018010003_add_back_indexes.rb

diff --git a/db/migrate/20111018010003_add_back_indexes.rb b/db/migrate/20111018010003_add_back_indexes.rb
new file mode 100644
index 0000000000..dcd13a6c05
--- /dev/null
+++ b/db/migrate/20111018010003_add_back_indexes.rb
@@ -0,0 +1,18 @@
+class AddBackIndexes < ActiveRecord::Migration
+  def self.up
+    # reduce index size
+    change_column :comments, :commentable_type, :string, :default => "Post", :null => false, :length => 60
+    change_column :share_visibilities, :shareable_type, :string, :default => "Post", :null => false, :length => 60
+
+    add_index :photos, :status_message_guid
+    add_index :comments, [:commentable_id, :commentable_type]
+  end
+
+  def self.down
+    remove_index :comments, :column => [:commentable_id, :commentable_type]
+    remove_index :photos, :column => :status_message_guid
+
+    change_column :share_visibilities, :shareable_type
+    change_column :comments, :commentable_type
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 19eec1a2a9..093e835720 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20111012215141) do
+ActiveRecord::Schema.define(:version => 20111018010003) do
 
   create_table "aspect_memberships", :force => true do |t|
     t.integer  "aspect_id",  :null => false
@@ -62,6 +62,7 @@ ActiveRecord::Schema.define(:version => 20111012215141) do
   end
 
   add_index "comments", ["author_id"], :name => "index_comments_on_person_id"
+  add_index "comments", ["commentable_id", "commentable_type"], :name => "index_comments_on_commentable_id_and_commentable_type"
   add_index "comments", ["guid"], :name => "index_comments_on_guid", :unique => true
 
   create_table "contacts", :force => true do |t|
@@ -262,6 +263,8 @@ ActiveRecord::Schema.define(:version => 20111012215141) do
     t.integer  "comments_count"
   end
 
+  add_index "photos", ["status_message_guid"], :name => "index_photos_on_status_message_guid"
+
   create_table "pods", :force => true do |t|
     t.string   "host"
     t.boolean  "ssl"
-- 
GitLab