Commit 792bbe3ca492a1ab3390f1dc8c56d14af0c67c1d
1 parent
08b8fb32
Exists in
master
and in
22 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,13 +18,13 @@ class Category < ActiveRecord::Base | ||
| 18 | acts_as_searchable :additional_fields => [{:name => {:boost => 2.0}}] | 18 | acts_as_searchable :additional_fields => [{:name => {:boost => 2.0}}] |
| 19 | handle_asynchronously :solr_save | 19 | handle_asynchronously :solr_save |
| 20 | 20 | ||
| 21 | - has_many :article_categorizations | 21 | + has_many :article_categorizations, :dependent => :destroy |
| 22 | has_many :articles, :through => :article_categorizations | 22 | has_many :articles, :through => :article_categorizations |
| 23 | has_many :comments, :through => :articles | 23 | has_many :comments, :through => :articles |
| 24 | 24 | ||
| 25 | has_many :events, :through => :article_categorizations, :class_name => 'Event', :source => :article | 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 | has_many :enterprises, :through => :profile_categorizations, :source => :profile, :class_name => 'Enterprise' | 28 | has_many :enterprises, :through => :profile_categorizations, :source => :profile, :class_name => 'Enterprise' |
| 29 | has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person' | 29 | has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person' |
| 30 | has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community' | 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 @@ | @@ -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,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 => 20120307200651) do | 12 | +ActiveRecord::Schema.define(:version => 20120402205653) do |
| 13 | 13 | ||
| 14 | create_table "abuse_reports", :force => true do |t| | 14 | create_table "abuse_reports", :force => true do |t| |
| 15 | t.integer "reporter_id" | 15 | t.integer "reporter_id" |
| @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 41 | end | 41 | end |
| 42 | 42 | ||
| 43 | add_index "action_tracker_notifications", ["action_tracker_id"], :name => "index_action_tracker_notifications_on_action_tracker_id" | 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 | add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id" | 45 | add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id" |
| 46 | 46 | ||
| 47 | create_table "article_versions", :force => true do |t| | 47 | create_table "article_versions", :force => true do |t| |
| @@ -159,7 +159,37 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -159,7 +159,37 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 159 | t.integer "position" | 159 | t.integer "position" |
| 160 | end | 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 | create_table "categories", :force => true do |t| | 194 | create_table "categories", :force => true do |t| |
| 165 | t.string "name" | 195 | t.string "name" |
| @@ -173,7 +203,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -173,7 +203,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 173 | t.float "lng" | 203 | t.float "lng" |
| 174 | t.boolean "display_in_menu", :default => false | 204 | t.boolean "display_in_menu", :default => false |
| 175 | t.integer "children_count", :default => 0 | 205 | t.integer "children_count", :default => 0 |
| 176 | - t.boolean "accept_products", :default => true | 206 | + t.boolean "accept_products" |
| 177 | t.integer "image_id" | 207 | t.integer "image_id" |
| 178 | t.string "acronym" | 208 | t.string "acronym" |
| 179 | t.string "abbreviation" | 209 | t.string "abbreviation" |
| @@ -253,6 +283,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -253,6 +283,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 253 | t.text "terms_of_use_acceptance_text" | 283 | t.text "terms_of_use_acceptance_text" |
| 254 | t.datetime "created_at" | 284 | t.datetime "created_at" |
| 255 | t.datetime "updated_at" | 285 | t.datetime "updated_at" |
| 286 | + t.text "send_email_plugin_allow_to" | ||
| 256 | t.integer "reports_lower_bound", :default => 0, :null => false | 287 | t.integer "reports_lower_bound", :default => 0, :null => false |
| 257 | end | 288 | end |
| 258 | 289 | ||
| @@ -308,6 +339,9 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -308,6 +339,9 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 308 | t.integer "unit_id" | 339 | t.integer "unit_id" |
| 309 | end | 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 | create_table "mailing_sents", :force => true do |t| | 345 | create_table "mailing_sents", :force => true do |t| |
| 312 | t.integer "mailing_id" | 346 | t.integer "mailing_id" |
| 313 | t.integer "person_id" | 347 | t.integer "person_id" |
| @@ -327,6 +361,28 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -327,6 +361,28 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 327 | t.datetime "updated_at" | 361 | t.datetime "updated_at" |
| 328 | end | 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 | create_table "national_region_types", :force => true do |t| | 386 | create_table "national_region_types", :force => true do |t| |
| 331 | t.string "name" | 387 | t.string "name" |
| 332 | end | 388 | end |
| @@ -351,17 +407,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -351,17 +407,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 351 | t.datetime "updated_at" | 407 | t.datetime "updated_at" |
| 352 | end | 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 | create_table "product_qualifiers", :force => true do |t| | 410 | create_table "product_qualifiers", :force => true do |t| |
| 366 | t.integer "product_id" | 411 | t.integer "product_id" |
| 367 | t.integer "qualifier_id" | 412 | t.integer "qualifier_id" |
| @@ -370,6 +415,10 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -370,6 +415,10 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 370 | t.datetime "updated_at" | 415 | t.datetime "updated_at" |
| 371 | end | 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 | create_table "production_costs", :force => true do |t| | 422 | create_table "production_costs", :force => true do |t| |
| 374 | t.string "name" | 423 | t.string "name" |
| 375 | t.integer "owner_id" | 424 | t.integer "owner_id" |
| @@ -386,8 +435,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -386,8 +435,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 386 | t.text "description" | 435 | t.text "description" |
| 387 | t.datetime "created_at" | 436 | t.datetime "created_at" |
| 388 | t.datetime "updated_at" | 437 | t.datetime "updated_at" |
| 389 | - t.float "lat" | ||
| 390 | - t.float "lng" | ||
| 391 | t.decimal "discount" | 438 | t.decimal "discount" |
| 392 | t.boolean "available", :default => true | 439 | t.boolean "available", :default => true |
| 393 | t.boolean "highlighted" | 440 | t.boolean "highlighted" |
| @@ -396,13 +443,14 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -396,13 +443,14 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 396 | end | 443 | end |
| 397 | 444 | ||
| 398 | add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id" | 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 | create_table "profiles", :force => true do |t| | 448 | create_table "profiles", :force => true do |t| |
| 401 | t.string "name" | 449 | t.string "name" |
| 402 | t.string "type" | 450 | t.string "type" |
| 403 | t.string "identifier" | 451 | t.string "identifier" |
| 404 | t.integer "environment_id" | 452 | t.integer "environment_id" |
| 405 | - t.boolean "active", :default => true | 453 | + t.boolean "active", :default => true |
| 406 | t.string "address" | 454 | t.string "address" |
| 407 | t.string "contact_phone" | 455 | t.string "contact_phone" |
| 408 | t.integer "home_page_id" | 456 | t.integer "home_page_id" |
| @@ -413,23 +461,29 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -413,23 +461,29 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 413 | t.float "lat" | 461 | t.float "lat" |
| 414 | t.float "lng" | 462 | t.float "lng" |
| 415 | t.integer "geocode_precision" | 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 | t.text "custom_header" | 466 | t.text "custom_header" |
| 419 | t.text "custom_footer" | 467 | t.text "custom_footer" |
| 420 | t.string "theme" | 468 | t.string "theme" |
| 421 | - t.boolean "public_profile", :default => true | 469 | + t.boolean "public_profile", :default => true |
| 422 | t.date "birth_date" | 470 | t.date "birth_date" |
| 423 | t.integer "preferred_domain_id" | 471 | t.integer "preferred_domain_id" |
| 424 | t.datetime "updated_at" | 472 | t.datetime "updated_at" |
| 425 | - t.boolean "visible", :default => true | 473 | + t.boolean "visible", :default => true |
| 426 | t.integer "image_id" | 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 | t.string "cnpj" | 481 | t.string "cnpj" |
| 429 | t.string "national_region_code" | 482 | t.string "national_region_code" |
| 430 | end | 483 | end |
| 431 | 484 | ||
| 432 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" | 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 | create_table "qualifier_certifiers", :force => true do |t| | 488 | create_table "qualifier_certifiers", :force => true do |t| |
| 435 | t.integer "qualifier_id" | 489 | t.integer "qualifier_id" |
| @@ -488,6 +542,15 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -488,6 +542,15 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 488 | t.datetime "updated_at" | 542 | t.datetime "updated_at" |
| 489 | end | 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 | create_table "taggings", :force => true do |t| | 554 | create_table "taggings", :force => true do |t| |
| 492 | t.integer "tag_id" | 555 | t.integer "tag_id" |
| 493 | t.integer "taggable_id" | 556 | t.integer "taggable_id" |
| @@ -515,6 +578,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | @@ -515,6 +578,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do | ||
| 515 | t.datetime "created_at" | 578 | t.datetime "created_at" |
| 516 | t.string "target_type" | 579 | t.string "target_type" |
| 517 | t.integer "image_id" | 580 | t.integer "image_id" |
| 581 | + t.integer "bsc_id" | ||
| 518 | end | 582 | end |
| 519 | 583 | ||
| 520 | create_table "thumbnails", :force => true do |t| | 584 | create_table "thumbnails", :force => true do |t| |