Commit 792bbe3ca492a1ab3390f1dc8c56d14af0c67c1d
1 parent
08b8fb32
Exists in
master
and in
29 other branches
Fix orphaned categorizations
Showing
3 changed files
with
103 additions
and
25 deletions
Show diff stats
app/models/category.rb
... | ... | @@ -18,13 +18,13 @@ class Category < ActiveRecord::Base |
18 | 18 | acts_as_searchable :additional_fields => [{:name => {:boost => 2.0}}] |
19 | 19 | handle_asynchronously :solr_save |
20 | 20 | |
21 | - has_many :article_categorizations | |
21 | + has_many :article_categorizations, :dependent => :destroy | |
22 | 22 | has_many :articles, :through => :article_categorizations |
23 | 23 | has_many :comments, :through => :articles |
24 | 24 | |
25 | 25 | has_many :events, :through => :article_categorizations, :class_name => 'Event', :source => :article |
26 | 26 | |
27 | - has_many :profile_categorizations | |
27 | + has_many :profile_categorizations, :dependent => :destroy | |
28 | 28 | has_many :enterprises, :through => :profile_categorizations, :source => :profile, :class_name => 'Enterprise' |
29 | 29 | has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person' |
30 | 30 | has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community' | ... | ... |
db/migrate/20120402205653_remove_broken_references_to_category.rb
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +class RemoveBrokenReferencesToCategory < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + execute <<-SQL | |
4 | + delete from articles_categories where category_id not in (select id from categories); | |
5 | + SQL | |
6 | + execute <<-SQL | |
7 | + delete from categories_profiles where category_id not in (select id from categories); | |
8 | + SQL | |
9 | + end | |
10 | + | |
11 | + def self.down | |
12 | + say "this migration can't be reverted" | |
13 | + end | |
14 | +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 => 20120307200651) do | |
12 | +ActiveRecord::Schema.define(:version => 20120402205653) do | |
13 | 13 | |
14 | 14 | create_table "abuse_reports", :force => true do |t| |
15 | 15 | t.integer "reporter_id" |
... | ... | @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
41 | 41 | end |
42 | 42 | |
43 | 43 | add_index "action_tracker_notifications", ["action_tracker_id"], :name => "index_action_tracker_notifications_on_action_tracker_id" |
44 | - add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notif_on_prof_id_act_tracker_id", :unique => true | |
44 | + add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notifications_on_profile_id_and_action_tra", :unique => true | |
45 | 45 | add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id" |
46 | 46 | |
47 | 47 | create_table "article_versions", :force => true do |t| |
... | ... | @@ -159,7 +159,37 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
159 | 159 | t.integer "position" |
160 | 160 | end |
161 | 161 | |
162 | - add_index "boxes", ["owner_id", "owner_type"], :name => "index_boxes_on_owner_type_and_owner_id" | |
162 | + add_index "boxes", ["owner_type", "owner_id"], :name => "index_boxes_on_owner_type_and_owner_id" | |
163 | + | |
164 | + create_table "bsc_plugin_contracts", :force => true do |t| | |
165 | + t.string "client_name" | |
166 | + t.integer "client_type" | |
167 | + t.integer "business_type" | |
168 | + t.string "state" | |
169 | + t.string "city" | |
170 | + t.integer "status", :default => 0 | |
171 | + t.integer "number_of_producers", :default => 0 | |
172 | + t.datetime "supply_start" | |
173 | + t.datetime "supply_end" | |
174 | + t.text "annotations" | |
175 | + t.integer "bsc_id" | |
176 | + t.datetime "created_at" | |
177 | + t.datetime "updated_at" | |
178 | + end | |
179 | + | |
180 | + create_table "bsc_plugin_contracts_enterprises", :id => false, :force => true do |t| | |
181 | + t.integer "contract_id" | |
182 | + t.integer "enterprise_id" | |
183 | + end | |
184 | + | |
185 | + create_table "bsc_plugin_sales", :force => true do |t| | |
186 | + t.integer "product_id", :null => false | |
187 | + t.integer "contract_id", :null => false | |
188 | + t.integer "quantity", :null => false | |
189 | + t.decimal "price" | |
190 | + t.datetime "created_at" | |
191 | + t.datetime "updated_at" | |
192 | + end | |
163 | 193 | |
164 | 194 | create_table "categories", :force => true do |t| |
165 | 195 | t.string "name" |
... | ... | @@ -173,7 +203,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
173 | 203 | t.float "lng" |
174 | 204 | t.boolean "display_in_menu", :default => false |
175 | 205 | t.integer "children_count", :default => 0 |
176 | - t.boolean "accept_products", :default => true | |
206 | + t.boolean "accept_products" | |
177 | 207 | t.integer "image_id" |
178 | 208 | t.string "acronym" |
179 | 209 | t.string "abbreviation" |
... | ... | @@ -253,6 +283,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
253 | 283 | t.text "terms_of_use_acceptance_text" |
254 | 284 | t.datetime "created_at" |
255 | 285 | t.datetime "updated_at" |
286 | + t.text "send_email_plugin_allow_to" | |
256 | 287 | t.integer "reports_lower_bound", :default => 0, :null => false |
257 | 288 | end |
258 | 289 | |
... | ... | @@ -308,6 +339,9 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
308 | 339 | t.integer "unit_id" |
309 | 340 | end |
310 | 341 | |
342 | + add_index "inputs", ["product_category_id"], :name => "index_inputs_on_product_category_id" | |
343 | + add_index "inputs", ["product_id"], :name => "index_inputs_on_product_id" | |
344 | + | |
311 | 345 | create_table "mailing_sents", :force => true do |t| |
312 | 346 | t.integer "mailing_id" |
313 | 347 | t.integer "person_id" |
... | ... | @@ -327,6 +361,28 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
327 | 361 | t.datetime "updated_at" |
328 | 362 | end |
329 | 363 | |
364 | + create_table "mezuro_plugin_metrics", :force => true do |t| | |
365 | + t.string "name" | |
366 | + t.float "value" | |
367 | + t.integer "metricable_id" | |
368 | + t.string "metricable_type" | |
369 | + t.datetime "created_at" | |
370 | + t.datetime "updated_at" | |
371 | + end | |
372 | + | |
373 | + create_table "mezuro_plugin_projects", :force => true do |t| | |
374 | + t.string "name" | |
375 | + t.string "identifier" | |
376 | + t.string "personal_webpage" | |
377 | + t.text "description" | |
378 | + t.string "repository_url" | |
379 | + t.string "svn_error" | |
380 | + t.boolean "with_tab" | |
381 | + t.integer "profile_id" | |
382 | + t.datetime "created_at" | |
383 | + t.datetime "updated_at" | |
384 | + end | |
385 | + | |
330 | 386 | create_table "national_region_types", :force => true do |t| |
331 | 387 | t.string "name" |
332 | 388 | end |
... | ... | @@ -351,17 +407,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
351 | 407 | t.datetime "updated_at" |
352 | 408 | end |
353 | 409 | |
354 | - create_table "product_categorizations", :force => true do |t| | |
355 | - t.integer "category_id" | |
356 | - t.integer "product_id" | |
357 | - t.boolean "virtual", :default => false | |
358 | - t.datetime "created_at" | |
359 | - t.datetime "updated_at" | |
360 | - end | |
361 | - | |
362 | - add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" | |
363 | - add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" | |
364 | - | |
365 | 410 | create_table "product_qualifiers", :force => true do |t| |
366 | 411 | t.integer "product_id" |
367 | 412 | t.integer "qualifier_id" |
... | ... | @@ -370,6 +415,10 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
370 | 415 | t.datetime "updated_at" |
371 | 416 | end |
372 | 417 | |
418 | + add_index "product_qualifiers", ["certifier_id"], :name => "index_product_qualifiers_on_certifier_id" | |
419 | + add_index "product_qualifiers", ["product_id"], :name => "index_product_qualifiers_on_product_id" | |
420 | + add_index "product_qualifiers", ["qualifier_id"], :name => "index_product_qualifiers_on_qualifier_id" | |
421 | + | |
373 | 422 | create_table "production_costs", :force => true do |t| |
374 | 423 | t.string "name" |
375 | 424 | t.integer "owner_id" |
... | ... | @@ -386,8 +435,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
386 | 435 | t.text "description" |
387 | 436 | t.datetime "created_at" |
388 | 437 | t.datetime "updated_at" |
389 | - t.float "lat" | |
390 | - t.float "lng" | |
391 | 438 | t.decimal "discount" |
392 | 439 | t.boolean "available", :default => true |
393 | 440 | t.boolean "highlighted" |
... | ... | @@ -396,13 +443,14 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
396 | 443 | end |
397 | 444 | |
398 | 445 | add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id" |
446 | + add_index "products", ["product_category_id"], :name => "index_products_on_product_category_id" | |
399 | 447 | |
400 | 448 | create_table "profiles", :force => true do |t| |
401 | 449 | t.string "name" |
402 | 450 | t.string "type" |
403 | 451 | t.string "identifier" |
404 | 452 | t.integer "environment_id" |
405 | - t.boolean "active", :default => true | |
453 | + t.boolean "active", :default => true | |
406 | 454 | t.string "address" |
407 | 455 | t.string "contact_phone" |
408 | 456 | t.integer "home_page_id" |
... | ... | @@ -413,23 +461,29 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
413 | 461 | t.float "lat" |
414 | 462 | t.float "lng" |
415 | 463 | t.integer "geocode_precision" |
416 | - t.boolean "enabled", :default => true | |
417 | - t.string "nickname", :limit => 16 | |
464 | + t.boolean "enabled", :default => true | |
465 | + t.string "nickname", :limit => 16 | |
418 | 466 | t.text "custom_header" |
419 | 467 | t.text "custom_footer" |
420 | 468 | t.string "theme" |
421 | - t.boolean "public_profile", :default => true | |
469 | + t.boolean "public_profile", :default => true | |
422 | 470 | t.date "birth_date" |
423 | 471 | t.integer "preferred_domain_id" |
424 | 472 | t.datetime "updated_at" |
425 | - t.boolean "visible", :default => true | |
473 | + t.boolean "visible", :default => true | |
426 | 474 | t.integer "image_id" |
427 | - t.boolean "validated", :default => true | |
475 | + t.integer "bsc_id" | |
476 | + t.string "company_name" | |
477 | + t.boolean "shopping_cart", :default => true | |
478 | + t.boolean "shopping_cart_delivery", :default => false | |
479 | + t.decimal "shopping_cart_delivery_price", :default => 0.0 | |
480 | + t.boolean "validated", :default => true | |
428 | 481 | t.string "cnpj" |
429 | 482 | t.string "national_region_code" |
430 | 483 | end |
431 | 484 | |
432 | 485 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" |
486 | + add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id" | |
433 | 487 | |
434 | 488 | create_table "qualifier_certifiers", :force => true do |t| |
435 | 489 | t.integer "qualifier_id" |
... | ... | @@ -488,6 +542,15 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
488 | 542 | t.datetime "updated_at" |
489 | 543 | end |
490 | 544 | |
545 | + create_table "shopping_cart_plugin_purchase_orders", :force => true do |t| | |
546 | + t.integer "customer_id" | |
547 | + t.integer "seller_id" | |
548 | + t.text "data" | |
549 | + t.integer "status" | |
550 | + t.datetime "created_at" | |
551 | + t.datetime "updated_at" | |
552 | + end | |
553 | + | |
491 | 554 | create_table "taggings", :force => true do |t| |
492 | 555 | t.integer "tag_id" |
493 | 556 | t.integer "taggable_id" |
... | ... | @@ -515,6 +578,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do |
515 | 578 | t.datetime "created_at" |
516 | 579 | t.string "target_type" |
517 | 580 | t.integer "image_id" |
581 | + t.integer "bsc_id" | |
518 | 582 | end |
519 | 583 | |
520 | 584 | create_table "thumbnails", :force => true do |t| | ... | ... |