Skip to content

Commit

Permalink
Merge pull request #58 from ZirconCode/master
Browse files Browse the repository at this point in the history
acts-as-taggable-on migration fix
  • Loading branch information
Bodacious committed Apr 15, 2014
2 parents fad05dd + a08edef commit 1eb6f68
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions db/migrate/20140414161010_add_taggings_counter_cache_to_tags.rb
@@ -0,0 +1,13 @@
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration
def self.up
add_column :tags, :taggings_count, :integer, :default => 0

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
21 changes: 21 additions & 0 deletions db/migrate/20140414162019_add_missing_unique_indices.rb
@@ -0,0 +1,21 @@
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

0 comments on commit 1eb6f68

Please sign in to comment.