Railsの勉強のために、少し応用的なブログサイトを開発しております。
投稿には、ユーザーが自由にタグを設定できる仕様です。
以前、acts-as-taggable-onというgemを利用してタグの仕組みを実装したのですが
勉強のためにgemのacts-as-taggable-onを利用せずにタグの仕組みを実装しようと試みております。
そこで1つ質問があります。
すでに実装したacts-as-taggable-onを削除するにはどのようにすればよろしいでしょうか?
以下の2つの作業をすれば良いと思いますが、どうでしょうか?
①モデルの記述を削除する
②マイグレーションファイルを削除する
①に関しましては以下のModelファイルの記述を削除すれば良いと思います。
Post.rb acts_as_taggable
しかし、acts-as-taggable-onを導入する際に生成された以下のマイグレーションファイルはどのようにして削除すればよろしいでしょうか?
# 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
# This migration comes from acts_as_taggable_on_engine (originally 1) class ActsAsTaggableOnMigration < ActiveRecord::Migration def self.up create_table :tags do |t| t.string :name end 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 # 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 end add_index :taggings, :tag_id add_index :taggings, [:taggable_id, :taggable_type, :context] end def self.down drop_table :taggings drop_table :tags end end
# 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
# This migration comes from acts_as_taggable_on_engine (originally 4) class AddMissingTaggableIndex < ActiveRecord::Migration 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
# 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 class ChangeCollationForTagNames < ActiveRecord::Migration def up if ActsAsTaggableOn::Utils.using_mysql? execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") end end end
上記のマイグレーションファイルは普通にdb/migrateの中のファイルごと削除して、再度「rake db:migrate」を実行すればよろしいでしょうか?
あまり、migration周りの知識がないため、アドバイスなどよろしくお願いいたします!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/02/14 02:57 編集