Commit 5189d47d91794bd5674fe6799e67be2939c4dc81
1 parent
58d64679
Exists in
master
and in
29 other branches
ActionItem514: adding indexes for common columns
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2217 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
49 additions
and
3 deletions
Show diff stats
... | ... | @@ -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 | ... | ... |
db/schema.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # |
10 | 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 | 14 | create_table "article_versions", :force => true do |t| |
15 | 15 | t.integer "article_id" |
... | ... | @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 45) do |
71 | 71 | t.boolean "virtual", :default => false |
72 | 72 | end |
73 | 73 | |
74 | - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" | |
75 | 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 | 77 | create_table "blocks", :force => true do |t| |
78 | 78 | t.string "title" |
... | ... | @@ -82,12 +82,16 @@ ActiveRecord::Schema.define(:version => 45) do |
82 | 82 | t.integer "position" |
83 | 83 | end |
84 | 84 | |
85 | + add_index "blocks", ["box_id"], :name => "index_blocks_on_box_id" | |
86 | + | |
85 | 87 | create_table "boxes", :force => true do |t| |
86 | 88 | t.string "owner_type" |
87 | 89 | t.integer "owner_id" |
88 | 90 | t.integer "position" |
89 | 91 | end |
90 | 92 | |
93 | + add_index "boxes", ["owner_type", "owner_id"], :name => "index_boxes_on_owner_type_and_owner_id" | |
94 | + | |
91 | 95 | create_table "categories", :force => true do |t| |
92 | 96 | t.string "name" |
93 | 97 | t.string "slug" |
... | ... | @@ -108,6 +112,9 @@ ActiveRecord::Schema.define(:version => 45) do |
108 | 112 | t.boolean "virtual", :default => false |
109 | 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 | 118 | create_table "comments", :force => true do |t| |
112 | 119 | t.string "title" |
113 | 120 | t.text "body" |
... | ... | @@ -170,6 +177,9 @@ ActiveRecord::Schema.define(:version => 45) do |
170 | 177 | t.datetime "updated_at" |
171 | 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 | 183 | create_table "products", :force => true do |t| |
174 | 184 | t.integer "enterprise_id" |
175 | 185 | t.integer "product_category_id" |
... | ... | @@ -183,6 +193,8 @@ ActiveRecord::Schema.define(:version => 45) do |
183 | 193 | t.float "lng" |
184 | 194 | end |
185 | 195 | |
196 | + add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id" | |
197 | + | |
186 | 198 | create_table "profiles", :force => true do |t| |
187 | 199 | t.string "name" |
188 | 200 | t.string "type" |
... | ... | @@ -202,6 +214,8 @@ ActiveRecord::Schema.define(:version => 45) do |
202 | 214 | t.boolean "enabled", :default => true |
203 | 215 | end |
204 | 216 | |
217 | + add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" | |
218 | + | |
205 | 219 | create_table "region_validators", :id => false, :force => true do |t| |
206 | 220 | t.integer "region_id" |
207 | 221 | t.integer "organization_id" |
... | ... | @@ -230,8 +244,8 @@ ActiveRecord::Schema.define(:version => 45) do |
230 | 244 | t.datetime "created_at" |
231 | 245 | end |
232 | 246 | |
233 | - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" | |
234 | 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 | 250 | create_table "tags", :force => true do |t| |
237 | 251 | t.string "name" | ... | ... |