Skip to content

Commit 163e0d1

Browse files
committed
Add AATO, create migration file.
1 parent 311cafe commit 163e0d1

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ gem 'bson_ext'
138138
#Tagging
139139
gem 'rocket_tag'
140140
gem 'squeel', '1.0.1'
141+
142+
gem 'acts-as-taggable-on', '~> 3.4'
143+
141144
gem 'strong_parameters'
142145
gem 'postgres_ext'
143146
# ElasticSearch client

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ GEM
8181
activesupport (3.2.21)
8282
i18n (~> 0.6, >= 0.6.4)
8383
multi_json (~> 1.0)
84+
acts-as-taggable-on (3.4.2)
85+
activerecord (>= 3.2, < 5)
8486
acts_as_commentable (2.0.1)
8587
acts_as_follower (0.1.1)
8688
addressable (2.3.6)
@@ -763,6 +765,7 @@ PLATFORMS
763765
ruby
764766

765767
DEPENDENCIES
768+
acts-as-taggable-on (~> 3.4)
766769
acts_as_commentable (= 2.0.1)
767770
acts_as_follower (= 0.1.1)
768771
airbrake
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class ReplaceRocketTagWithAato < ActiveRecord::Migration
2+
def up
3+
# This was created by rocket_tag but not used anywhere.
4+
drop_table :alias_tags
5+
6+
# This is something that AATO has that rocket_tag doesn't.
7+
add_column :tags, :taggings_count, :integer, default: 0
8+
9+
# Populate the taggings_count properly
10+
ActsAsTaggableOn::Tag.reset_column_information
11+
ActsAsTaggableOn::Tag.find_each do |tag|
12+
ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
13+
end
14+
15+
add_index 'tags', ['name'], name: 'index_tags_on_name', unique: true
16+
17+
remove_index 'taggings', name: "index_taggings_on_tag_id"
18+
remove_index 'taggings', name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
19+
add_index 'taggings',
20+
['tag_id', 'taggable_id', 'taggable_type', 'context', 'tagger_id', 'tagger_type'],
21+
unique: true, name: 'taggings_idx'
22+
end
23+
24+
def down
25+
raise ActiveRecord::IrreversibleMigration
26+
end
27+
end

db/schema.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,11 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20141221211825) do
14+
ActiveRecord::Schema.define(:version => 20141231203425) do
1515

1616
add_extension "citext"
1717
add_extension "hstore"
1818

19-
create_table "alias_tags", :id => false, :force => true do |t|
20-
t.integer "tag_id"
21-
t.integer "alias_id"
22-
end
23-
24-
add_index "alias_tags", ["alias_id"], :name => "index_alias_tags_on_alias_id"
25-
add_index "alias_tags", ["tag_id"], :name => "index_alias_tags_on_tag_id"
26-
2719
create_table "api_accesses", :force => true do |t|
2820
t.string "api_key"
2921
t.text "awards"
@@ -352,13 +344,15 @@
352344
t.datetime "created_at"
353345
end
354346

355-
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
356-
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
347+
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], :name => "taggings_idx", :unique => true
357348

358349
create_table "tags", :force => true do |t|
359-
t.string "name"
350+
t.string "name"
351+
t.integer "taggings_count", :default => 0
360352
end
361353

354+
add_index "tags", ["name"], :name => "index_tags_on_name", :unique => true
355+
362356
create_table "teams", :force => true do |t|
363357
t.datetime "created_at", :null => false
364358
t.datetime "updated_at", :null => false

0 commit comments

Comments
 (0)