Skip to content

Commit

Permalink
Fixes #21766 - Enforce uniquness of TaxableTaxonomy in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrisker committed Nov 27, 2017
1 parent fd68eb6 commit d6c62c9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions db/migrate/20171126131104_remove_duplicate_taxable_taxonomies.rb
@@ -0,0 +1,13 @@
class RemoveDuplicateTaxableTaxonomies < ActiveRecord::Migration
def up
deduped = TaxableTaxonomy.group(:taxonomy_id, :taxable_id, :taxable_type).pluck('min(id)')
TaxableTaxonomy.where.not(id: deduped).delete_all
remove_index :taxable_taxonomies, :name => 'taxable_index'
add_index :taxable_taxonomies, [:taxable_id, :taxable_type, :taxonomy_id], :name => 'taxable_index', :unique => true
end

def down
remove_index :taxable_taxonomies, :name => 'taxable_index'
add_index :taxable_taxonomies, [:taxable_id, :taxable_type, :taxonomy_id], :name => 'taxable_index'
end
end

0 comments on commit d6c62c9

Please sign in to comment.