Commit 5189d47d91794bd5674fe6799e67be2939c4dc81

Authored by AntonioTerceiro
1 parent 58d64679

ActionItem514: adding indexes for common columns

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2217 3f533792-8f58-4932-b0fe-aaf55b0a4547
db/migrate/046_aggressive_indexing_strategy1.rb 0 → 100644
@@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
  1 +class AggressiveIndexingStrategy1 < ActiveRecord::Migration
  2 + def self.up
  3 + # profile categorizations
  4 + add_index(:categories_profiles, :profile_id)
  5 + add_index(:categories_profiles, :category_id)
  6 +
  7 + # product categorizations
  8 + add_index(:product_categorizations, :product_id)
  9 + add_index(:product_categorizations, :category_id)
  10 +
  11 + # finding products by the enterprises that own them
  12 + add_index(:products, :enterprise_id)
  13 +
  14 + # finding profiles by their environment
  15 + add_index(:profiles, :environment_id)
  16 +
  17 + # finding blocks by their box, and boxes by their owner
  18 + add_index(:blocks, :box_id)
  19 + add_index(:boxes, [:owner_type, :owner_id])
  20 + end
  21 +
  22 + def self.down
  23 + add_index(:categories_profiles, :column => :profile_id)
  24 + add_index(:categories_profiles, :column => :category_id)
  25 + add_index(:product_categorizations, :column => :product_id)
  26 + add_index(:product_categorizations, :column => :category_id)
  27 + add_index(:products, :column => :enterprise_id)
  28 + add_index(:profiles, :column => :environment_id)
  29 + add_index(:blocks, :column => :box_id)
  30 + add_index(:box, :column => [:owner_type, :owner_id])
  31 + end
  32 +end
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 # 9 #
10 # It's strongly recommended to check this file into your version control system. 10 # It's strongly recommended to check this file into your version control system.
11 11
12 -ActiveRecord::Schema.define(:version => 45) do 12 +ActiveRecord::Schema.define(:version => 46) do
13 13
14 create_table "article_versions", :force => true do |t| 14 create_table "article_versions", :force => true do |t|
15 t.integer "article_id" 15 t.integer "article_id"
@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
71 t.boolean "virtual", :default => false 71 t.boolean "virtual", :default => false
72 end 72 end
73 73
74 - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"  
75 add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" 74 add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"
  75 + add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"
76 76
77 create_table "blocks", :force => true do |t| 77 create_table "blocks", :force => true do |t|
78 t.string "title" 78 t.string "title"
@@ -82,12 +82,16 @@ ActiveRecord::Schema.define(:version =&gt; 45) do @@ -82,12 +82,16 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
82 t.integer "position" 82 t.integer "position"
83 end 83 end
84 84
  85 + add_index "blocks", ["box_id"], :name => "index_blocks_on_box_id"
  86 +
85 create_table "boxes", :force => true do |t| 87 create_table "boxes", :force => true do |t|
86 t.string "owner_type" 88 t.string "owner_type"
87 t.integer "owner_id" 89 t.integer "owner_id"
88 t.integer "position" 90 t.integer "position"
89 end 91 end
90 92
  93 + add_index "boxes", ["owner_type", "owner_id"], :name => "index_boxes_on_owner_type_and_owner_id"
  94 +
91 create_table "categories", :force => true do |t| 95 create_table "categories", :force => true do |t|
92 t.string "name" 96 t.string "name"
93 t.string "slug" 97 t.string "slug"
@@ -108,6 +112,9 @@ ActiveRecord::Schema.define(:version =&gt; 45) do @@ -108,6 +112,9 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
108 t.boolean "virtual", :default => false 112 t.boolean "virtual", :default => false
109 end 113 end
110 114
  115 + add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id"
  116 + add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id"
  117 +
111 create_table "comments", :force => true do |t| 118 create_table "comments", :force => true do |t|
112 t.string "title" 119 t.string "title"
113 t.text "body" 120 t.text "body"
@@ -170,6 +177,9 @@ ActiveRecord::Schema.define(:version =&gt; 45) do @@ -170,6 +177,9 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
170 t.datetime "updated_at" 177 t.datetime "updated_at"
171 end 178 end
172 179
  180 + add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id"
  181 + add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id"
  182 +
173 create_table "products", :force => true do |t| 183 create_table "products", :force => true do |t|
174 t.integer "enterprise_id" 184 t.integer "enterprise_id"
175 t.integer "product_category_id" 185 t.integer "product_category_id"
@@ -183,6 +193,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do @@ -183,6 +193,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
183 t.float "lng" 193 t.float "lng"
184 end 194 end
185 195
  196 + add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id"
  197 +
186 create_table "profiles", :force => true do |t| 198 create_table "profiles", :force => true do |t|
187 t.string "name" 199 t.string "name"
188 t.string "type" 200 t.string "type"
@@ -202,6 +214,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do @@ -202,6 +214,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
202 t.boolean "enabled", :default => true 214 t.boolean "enabled", :default => true
203 end 215 end
204 216
  217 + add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id"
  218 +
205 create_table "region_validators", :id => false, :force => true do |t| 219 create_table "region_validators", :id => false, :force => true do |t|
206 t.integer "region_id" 220 t.integer "region_id"
207 t.integer "organization_id" 221 t.integer "organization_id"
@@ -230,8 +244,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do @@ -230,8 +244,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
230 t.datetime "created_at" 244 t.datetime "created_at"
231 end 245 end
232 246
233 - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"  
234 add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" 247 add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
  248 + add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"
235 249
236 create_table "tags", :force => true do |t| 250 create_table "tags", :force => true do |t|
237 t.string "name" 251 t.string "name"