From 70364c9e42a52dc653f1619d84b168af2d4f4cae Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sun, 9 Sep 2018 13:14:27 +0000 Subject: [PATCH 3/3] merge migrations --- ...able_on_migration.acts_as_taggable_on_engine.rb | 57 ++++++++++++++-------- ...ng_unique_indices.acts_as_taggable_on_engine.rb | 26 ---------- ...ter_cache_to_tags.acts_as_taggable_on_engine.rb | 12 ++--- ...ng_taggable_index.acts_as_taggable_on_engine.rb | 15 ------ ...ion_for_tag_names.acts_as_taggable_on_engine.rb | 10 +--- ...dexes_on_taggings.acts_as_taggable_on_engine.rb | 23 --------- 6 files changed, 42 insertions(+), 101 deletions(-) delete mode 100644 db/migrate/20180802191933_add_missing_unique_indices.acts_as_taggable_on_engine.rb delete mode 100644 db/migrate/20180802191935_add_missing_taggable_index.acts_as_taggable_on_engine.rb delete mode 100644 db/migrate/20180802191937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb diff --git a/db/migrate/20180802191932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20180802191932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb index 461eae4..ca1bd03 100644 --- a/db/migrate/20180802191932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +++ b/db/migrate/20180802191932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb @@ -1,32 +1,49 @@ -# This migration comes from acts_as_taggable_on_engine (originally 1) -if ActiveRecord.gem_version >= Gem::Version.new('5.0') - class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end -else - class ActsAsTaggableOnMigration < ActiveRecord::Migration; end -end -ActsAsTaggableOnMigration.class_eval do +class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2] def self.up - create_table :tags do |t| - t.string :name + unless table_exists?(:tags) + create_table :tags do |t| + t.string :name + end end - create_table :taggings do |t| - t.references :tag + unless table_exists?(:taggings) + create_table :taggings do |t| + t.references :tag - # You should make sure that the column created is - # long enough to store the required class names. - t.references :taggable, polymorphic: true - t.references :tagger, polymorphic: true + # You should make sure that the column created is + # long enough to store the required class names. + t.references :taggable, polymorphic: true + t.references :tagger, polymorphic: true - # Limit is created to prevent MySQL error on index - # length for MyISAM table type: http://bit.ly/vgW2Ql - t.string :context, limit: 128 + # Limit is created to prevent MySQL error on index + # length for MyISAM table type: http://bit.ly/vgW2Ql + t.string :context, limit: 128 - t.datetime :created_at + t.datetime :created_at + end end - add_index :taggings, :tag_id + add_index :tags, :name, unique: true unless index_exists?(:tags, :name) add_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id + add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id + add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type + add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id + add_index :taggings, :context unless index_exists? :taggings, :context + + unless index_exists? :taggings, [:tagger_id, :tagger_type] + add_index :taggings, [:tagger_id, :tagger_type] + end + + unless index_exists? :taggings, [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], unique: true, name: 'taggings_idx' + add_index :taggings, + [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], + unique: true, name: 'taggings_idx' + end + + unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + end end def self.down diff --git a/db/migrate/20180802191933_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20180802191933_add_missing_unique_indices.acts_as_taggable_on_engine.rb deleted file mode 100644 index 514ac57..0000000 --- a/db/migrate/20180802191933_add_missing_unique_indices.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,26 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 2) -if ActiveRecord.gem_version >= Gem::Version.new('5.0') - class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end -else - class AddMissingUniqueIndices < ActiveRecord::Migration; end -end -AddMissingUniqueIndices.class_eval do - def self.up - add_index :tags, :name, unique: true - - remove_index :taggings, :tag_id if index_exists?(: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 unless index_exists?(:taggings, :tag_id) - add_index :taggings, [:taggable_id, :taggable_type, :context] - end -end diff --git a/db/migrate/20180802191934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20180802191934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb index 1d9b556..a1402c0 100644 --- a/db/migrate/20180802191934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +++ b/db/migrate/20180802191934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -1,12 +1,8 @@ -# This migration comes from acts_as_taggable_on_engine (originally 3) -if ActiveRecord.gem_version >= Gem::Version.new('5.0') - class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end -else - class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end -end -AddTaggingsCounterCacheToTags.class_eval do +class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2] def self.up - add_column :tags, :taggings_count, :integer, default: 0 + unless column_exists?(:tags, :taggings_count, :integer) + add_column :tags, :taggings_count, :integer, default: 0 + end ActsAsTaggableOn::Tag.reset_column_information ActsAsTaggableOn::Tag.find_each do |tag| diff --git a/db/migrate/20180802191935_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20180802191935_add_missing_taggable_index.acts_as_taggable_on_engine.rb deleted file mode 100644 index 5f46569..0000000 --- a/db/migrate/20180802191935_add_missing_taggable_index.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,15 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 4) -if ActiveRecord.gem_version >= Gem::Version.new('5.0') - class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end -else - class AddMissingTaggableIndex < ActiveRecord::Migration; end -end -AddMissingTaggableIndex.class_eval do - def self.up - add_index :taggings, [:taggable_id, :taggable_type, :context] - end - - def self.down - remove_index :taggings, [:taggable_id, :taggable_type, :context] - end -end diff --git a/db/migrate/20180802191936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20180802191936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb index f119b16..b242fb7 100644 --- a/db/migrate/20180802191936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +++ b/db/migrate/20180802191936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb @@ -1,12 +1,4 @@ -# This migration comes from acts_as_taggable_on_engine (originally 5) -# This migration is added to circumvent issue #623 and have special characters -# work properly -if ActiveRecord.gem_version >= Gem::Version.new('5.0') - class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end -else - class ChangeCollationForTagNames < ActiveRecord::Migration; end -end -ChangeCollationForTagNames.class_eval do +class ChangeCollationForTagNames < ActiveRecord::Migration[4.2] def up if ActsAsTaggableOn::Utils.using_mysql? execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") diff --git a/db/migrate/20180802191937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20180802191937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb deleted file mode 100644 index 94e1f2e..0000000 --- a/db/migrate/20180802191937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,23 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 6) -if ActiveRecord.gem_version >= Gem::Version.new('5.0') - class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end -else - class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end -end -AddMissingIndexesOnTaggings.class_eval do - def change - add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id - add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id - add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type - add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id - add_index :taggings, :context unless index_exists? :taggings, :context - - unless index_exists? :taggings, [:tagger_id, :tagger_type] - add_index :taggings, [:tagger_id, :tagger_type] - end - - unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' - add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' - end - end -end -- 2.1.4