diff --git a/db/migrate/20210212143002_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20210212143002_add_missing_unique_indices.acts_as_taggable_on_engine.rb index 0d621815e..e17b2a52f 100644 --- a/db/migrate/20210212143002_add_missing_unique_indices.acts_as_taggable_on_engine.rb +++ b/db/migrate/20210212143002_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -8,11 +8,15 @@ class AddMissingUniqueIndices < ActiveRecord::Migration; end def self.up add_index ActsAsTaggableOn.tags_table, :name, unique: true - remove_index ActsAsTaggableOn.taggings_table, :tag_id if index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) + if index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) + remove_foreign_key :taggings, :tags + remove_index ActsAsTaggableOn.taggings_table, :tag_id + end remove_index ActsAsTaggableOn.taggings_table, name: "taggings_taggable_context_idx" add_index ActsAsTaggableOn.taggings_table, [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], unique: true, name: "taggings_idx" + add_foreign_key ActsAsTaggableOn.taggings_table, ActsAsTaggableOn.tags_table, column: 'tag_id' end def self.down