From fb3b70a6dcb0a47ce1b76ff172d5584811c9fee2 Mon Sep 17 00:00:00 2001 From: Alexander Negoda Date: Sun, 22 Jun 2014 17:30:46 +0400 Subject: added new migrations for acts-as-taggable-on engine --- ...sing_unique_indices.acts_as_taggable_on_engine.rb | 20 ++++++++++++++++++++ ...unter_cache_to_tags.acts_as_taggable_on_engine.rb | 15 +++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 db/migrate/20140622132537_add_missing_unique_indices.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20140622132538_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb (limited to 'db') diff --git a/db/migrate/20140622132537_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20140622132537_add_missing_unique_indices.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..4ca676f --- /dev/null +++ b/db/migrate/20140622132537_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -0,0 +1,20 @@ +# This migration comes from acts_as_taggable_on_engine (originally 2) +class AddMissingUniqueIndices < ActiveRecord::Migration + def self.up + add_index :tags, :name, unique: true + + remove_index :taggings, :tag_id + remove_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, + [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], + unique: true, name: 'taggings_idx' + end + + def self.down + remove_index :tags, :name + + remove_index :taggings, name: 'taggings_idx' + add_index :taggings, :tag_id + add_index :taggings, [:taggable_id, :taggable_type, :context] + end +end diff --git a/db/migrate/20140622132538_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20140622132538_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..8edb508 --- /dev/null +++ b/db/migrate/20140622132538_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -0,0 +1,15 @@ +# This migration comes from acts_as_taggable_on_engine (originally 3) +class AddTaggingsCounterCacheToTags < ActiveRecord::Migration + def self.up + add_column :tags, :taggings_count, :integer, default: 0 + + ActsAsTaggableOn::Tag.reset_column_information + ActsAsTaggableOn::Tag.find_each do |tag| + ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings) + end + end + + def self.down + remove_column :tags, :taggings_count + end +end -- cgit v1.2.3