From 792bbe3ca492a1ab3390f1dc8c56d14af0c67c1d Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 3 Apr 2012 18:34:24 -0300 Subject: [PATCH] Fix orphaned categorizations --- app/models/category.rb | 4 ++-- db/migrate/20120402205653_remove_broken_references_to_category.rb | 14 ++++++++++++++ db/schema.rb | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- 3 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 db/migrate/20120402205653_remove_broken_references_to_category.rb diff --git a/app/models/category.rb b/app/models/category.rb index 7c124ea..ab48d18 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -18,13 +18,13 @@ class Category < ActiveRecord::Base acts_as_searchable :additional_fields => [{:name => {:boost => 2.0}}] handle_asynchronously :solr_save - has_many :article_categorizations + has_many :article_categorizations, :dependent => :destroy has_many :articles, :through => :article_categorizations has_many :comments, :through => :articles has_many :events, :through => :article_categorizations, :class_name => 'Event', :source => :article - has_many :profile_categorizations + has_many :profile_categorizations, :dependent => :destroy has_many :enterprises, :through => :profile_categorizations, :source => :profile, :class_name => 'Enterprise' has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person' has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community' diff --git a/db/migrate/20120402205653_remove_broken_references_to_category.rb b/db/migrate/20120402205653_remove_broken_references_to_category.rb new file mode 100644 index 0000000..220802c --- /dev/null +++ b/db/migrate/20120402205653_remove_broken_references_to_category.rb @@ -0,0 +1,14 @@ +class RemoveBrokenReferencesToCategory < ActiveRecord::Migration + def self.up + execute <<-SQL + delete from articles_categories where category_id not in (select id from categories); + SQL + execute <<-SQL + delete from categories_profiles where category_id not in (select id from categories); + SQL + end + + def self.down + say "this migration can't be reverted" + end +end diff --git a/db/schema.rb b/db/schema.rb index d56caa7..ce8f289 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120307200651) do +ActiveRecord::Schema.define(:version => 20120402205653) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do end add_index "action_tracker_notifications", ["action_tracker_id"], :name => "index_action_tracker_notifications_on_action_tracker_id" - add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notif_on_prof_id_act_tracker_id", :unique => true + add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notifications_on_profile_id_and_action_tra", :unique => true add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id" create_table "article_versions", :force => true do |t| @@ -159,7 +159,37 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.integer "position" end - add_index "boxes", ["owner_id", "owner_type"], :name => "index_boxes_on_owner_type_and_owner_id" + add_index "boxes", ["owner_type", "owner_id"], :name => "index_boxes_on_owner_type_and_owner_id" + + create_table "bsc_plugin_contracts", :force => true do |t| + t.string "client_name" + t.integer "client_type" + t.integer "business_type" + t.string "state" + t.string "city" + t.integer "status", :default => 0 + t.integer "number_of_producers", :default => 0 + t.datetime "supply_start" + t.datetime "supply_end" + t.text "annotations" + t.integer "bsc_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "bsc_plugin_contracts_enterprises", :id => false, :force => true do |t| + t.integer "contract_id" + t.integer "enterprise_id" + end + + create_table "bsc_plugin_sales", :force => true do |t| + t.integer "product_id", :null => false + t.integer "contract_id", :null => false + t.integer "quantity", :null => false + t.decimal "price" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "categories", :force => true do |t| t.string "name" @@ -173,7 +203,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.float "lng" t.boolean "display_in_menu", :default => false t.integer "children_count", :default => 0 - t.boolean "accept_products", :default => true + t.boolean "accept_products" t.integer "image_id" t.string "acronym" t.string "abbreviation" @@ -253,6 +283,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.text "terms_of_use_acceptance_text" t.datetime "created_at" t.datetime "updated_at" + t.text "send_email_plugin_allow_to" t.integer "reports_lower_bound", :default => 0, :null => false end @@ -308,6 +339,9 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.integer "unit_id" end + add_index "inputs", ["product_category_id"], :name => "index_inputs_on_product_category_id" + add_index "inputs", ["product_id"], :name => "index_inputs_on_product_id" + create_table "mailing_sents", :force => true do |t| t.integer "mailing_id" t.integer "person_id" @@ -327,6 +361,28 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.datetime "updated_at" end + create_table "mezuro_plugin_metrics", :force => true do |t| + t.string "name" + t.float "value" + t.integer "metricable_id" + t.string "metricable_type" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "mezuro_plugin_projects", :force => true do |t| + t.string "name" + t.string "identifier" + t.string "personal_webpage" + t.text "description" + t.string "repository_url" + t.string "svn_error" + t.boolean "with_tab" + t.integer "profile_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "national_region_types", :force => true do |t| t.string "name" end @@ -351,17 +407,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.datetime "updated_at" end - create_table "product_categorizations", :force => true do |t| - t.integer "category_id" - t.integer "product_id" - t.boolean "virtual", :default => false - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" - add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" - create_table "product_qualifiers", :force => true do |t| t.integer "product_id" t.integer "qualifier_id" @@ -370,6 +415,10 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.datetime "updated_at" end + add_index "product_qualifiers", ["certifier_id"], :name => "index_product_qualifiers_on_certifier_id" + add_index "product_qualifiers", ["product_id"], :name => "index_product_qualifiers_on_product_id" + add_index "product_qualifiers", ["qualifier_id"], :name => "index_product_qualifiers_on_qualifier_id" + create_table "production_costs", :force => true do |t| t.string "name" t.integer "owner_id" @@ -386,8 +435,6 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.text "description" t.datetime "created_at" t.datetime "updated_at" - t.float "lat" - t.float "lng" t.decimal "discount" t.boolean "available", :default => true t.boolean "highlighted" @@ -396,13 +443,14 @@ ActiveRecord::Schema.define(:version => 20120307200651) do end add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id" + add_index "products", ["product_category_id"], :name => "index_products_on_product_category_id" create_table "profiles", :force => true do |t| t.string "name" t.string "type" t.string "identifier" t.integer "environment_id" - t.boolean "active", :default => true + t.boolean "active", :default => true t.string "address" t.string "contact_phone" t.integer "home_page_id" @@ -413,23 +461,29 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.float "lat" t.float "lng" t.integer "geocode_precision" - t.boolean "enabled", :default => true - t.string "nickname", :limit => 16 + t.boolean "enabled", :default => true + t.string "nickname", :limit => 16 t.text "custom_header" t.text "custom_footer" t.string "theme" - t.boolean "public_profile", :default => true + t.boolean "public_profile", :default => true t.date "birth_date" t.integer "preferred_domain_id" t.datetime "updated_at" - t.boolean "visible", :default => true + t.boolean "visible", :default => true t.integer "image_id" - t.boolean "validated", :default => true + t.integer "bsc_id" + t.string "company_name" + t.boolean "shopping_cart", :default => true + t.boolean "shopping_cart_delivery", :default => false + t.decimal "shopping_cart_delivery_price", :default => 0.0 + t.boolean "validated", :default => true t.string "cnpj" t.string "national_region_code" end add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" + add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id" create_table "qualifier_certifiers", :force => true do |t| t.integer "qualifier_id" @@ -488,6 +542,15 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.datetime "updated_at" end + create_table "shopping_cart_plugin_purchase_orders", :force => true do |t| + t.integer "customer_id" + t.integer "seller_id" + t.text "data" + t.integer "status" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "taggings", :force => true do |t| t.integer "tag_id" t.integer "taggable_id" @@ -515,6 +578,7 @@ ActiveRecord::Schema.define(:version => 20120307200651) do t.datetime "created_at" t.string "target_type" t.integer "image_id" + t.integer "bsc_id" end create_table "thumbnails", :force => true do |t| -- libgit2 0.21.2