about summary refs log tree commit diff stats
path: root/db/migrate
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-07-07 16:23:04 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-07-07 16:23:04 -0400
commit42d9db526d3aef2e08848d6bc587feaf3700db42 (patch)
tree29bfcb6653bb6419fa087f87de72b00b00e68fd6 /db/migrate
parentdd231a335758873dcd9024db7618837094fcc0a5 (diff)
downloadthoughts-42d9db526d3aef2e08848d6bc587feaf3700db42.tar.gz
thoughts-42d9db526d3aef2e08848d6bc587feaf3700db42.tar.bz2
thoughts-42d9db526d3aef2e08848d6bc587feaf3700db42.zip
Added tags
Blogs and streams can now be tagged. Records now show the appropriate tags for an entry. Updates work oddly, because their records show the stream's tags, since updates do not have tags themselves.

refs #2
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20180707142415_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb36
-rw-r--r--db/migrate/20180707142416_add_missing_unique_indices.acts_as_taggable_on_engine.rb26
-rw-r--r--db/migrate/20180707142417_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb20
-rw-r--r--db/migrate/20180707142418_add_missing_taggable_index.acts_as_taggable_on_engine.rb15
-rw-r--r--db/migrate/20180707142419_change_collation_for_tag_names.acts_as_taggable_on_engine.rb15
-rw-r--r--db/migrate/20180707142420_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb23
6 files changed, 135 insertions, 0 deletions
diff --git a/db/migrate/20180707142415_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20180707142415_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..461eae4 --- /dev/null +++ b/db/migrate/20180707142415_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb
@@ -0,0 +1,36 @@
1# This migration comes from acts_as_taggable_on_engine (originally 1)
2if ActiveRecord.gem_version >= Gem::Version.new('5.0')
3 class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end
4else
5 class ActsAsTaggableOnMigration < ActiveRecord::Migration; end
6end
7ActsAsTaggableOnMigration.class_eval do
8 def self.up
9 create_table :tags do |t|
10 t.string :name
11 end
12
13 create_table :taggings do |t|
14 t.references :tag
15
16 # You should make sure that the column created is
17 # long enough to store the required class names.
18 t.references :taggable, polymorphic: true
19 t.references :tagger, polymorphic: true
20
21 # Limit is created to prevent MySQL error on index
22 # length for MyISAM table type: http://bit.ly/vgW2Ql
23 t.string :context, limit: 128
24
25 t.datetime :created_at
26 end
27
28 add_index :taggings, :tag_id
29 add_index :taggings, [:taggable_id, :taggable_type, :context]
30 end
31
32 def self.down
33 drop_table :taggings
34 drop_table :tags
35 end
36end
diff --git a/db/migrate/20180707142416_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20180707142416_add_missing_unique_indices.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..514ac57 --- /dev/null +++ b/db/migrate/20180707142416_add_missing_unique_indices.acts_as_taggable_on_engine.rb
@@ -0,0 +1,26 @@
1# This migration comes from acts_as_taggable_on_engine (originally 2)
2if ActiveRecord.gem_version >= Gem::Version.new('5.0')
3 class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end
4else
5 class AddMissingUniqueIndices < ActiveRecord::Migration; end
6end
7AddMissingUniqueIndices.class_eval do
8 def self.up
9 add_index :tags, :name, unique: true
10
11 remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id)
12 remove_index :taggings, [:taggable_id, :taggable_type, :context]
13 add_index :taggings,
14 [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
15 unique: true, name: 'taggings_idx'
16 end
17
18 def self.down
19 remove_index :tags, :name
20
21 remove_index :taggings, name: 'taggings_idx'
22
23 add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)
24 add_index :taggings, [:taggable_id, :taggable_type, :context]
25 end
26end
diff --git a/db/migrate/20180707142417_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20180707142417_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..1d9b556 --- /dev/null +++ b/db/migrate/20180707142417_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb
@@ -0,0 +1,20 @@
1# This migration comes from acts_as_taggable_on_engine (originally 3)
2if ActiveRecord.gem_version >= Gem::Version.new('5.0')
3 class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end
4else
5 class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end
6end
7AddTaggingsCounterCacheToTags.class_eval do
8 def self.up
9 add_column :tags, :taggings_count, :integer, default: 0
10
11 ActsAsTaggableOn::Tag.reset_column_information
12 ActsAsTaggableOn::Tag.find_each do |tag|
13 ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
14 end
15 end
16
17 def self.down
18 remove_column :tags, :taggings_count
19 end
20end
diff --git a/db/migrate/20180707142418_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20180707142418_add_missing_taggable_index.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..5f46569 --- /dev/null +++ b/db/migrate/20180707142418_add_missing_taggable_index.acts_as_taggable_on_engine.rb
@@ -0,0 +1,15 @@
1# This migration comes from acts_as_taggable_on_engine (originally 4)
2if ActiveRecord.gem_version >= Gem::Version.new('5.0')
3 class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end
4else
5 class AddMissingTaggableIndex < ActiveRecord::Migration; end
6end
7AddMissingTaggableIndex.class_eval do
8 def self.up
9 add_index :taggings, [:taggable_id, :taggable_type, :context]
10 end
11
12 def self.down
13 remove_index :taggings, [:taggable_id, :taggable_type, :context]
14 end
15end
diff --git a/db/migrate/20180707142419_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20180707142419_change_collation_for_tag_names.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..f119b16 --- /dev/null +++ b/db/migrate/20180707142419_change_collation_for_tag_names.acts_as_taggable_on_engine.rb
@@ -0,0 +1,15 @@
1# This migration comes from acts_as_taggable_on_engine (originally 5)
2# This migration is added to circumvent issue #623 and have special characters
3# work properly
4if ActiveRecord.gem_version >= Gem::Version.new('5.0')
5 class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end
6else
7 class ChangeCollationForTagNames < ActiveRecord::Migration; end
8end
9ChangeCollationForTagNames.class_eval do
10 def up
11 if ActsAsTaggableOn::Utils.using_mysql?
12 execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
13 end
14 end
15end
diff --git a/db/migrate/20180707142420_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20180707142420_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..94e1f2e --- /dev/null +++ b/db/migrate/20180707142420_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb
@@ -0,0 +1,23 @@
1# This migration comes from acts_as_taggable_on_engine (originally 6)
2if ActiveRecord.gem_version >= Gem::Version.new('5.0')
3 class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end
4else
5 class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end
6end
7AddMissingIndexesOnTaggings.class_eval do
8 def change
9 add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id
10 add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id
11 add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type
12 add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id
13 add_index :taggings, :context unless index_exists? :taggings, :context
14
15 unless index_exists? :taggings, [:tagger_id, :tagger_type]
16 add_index :taggings, [:tagger_id, :tagger_type]
17 end
18
19 unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
20 add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
21 end
22 end
23end