Sha256: b154f9ae1c83c07d61fb8b27babaae81d8eac2d4f216e18879869d26604e809f
Contents?: true
Size: 662 Bytes
Versions: 8
Compression:
Stored size: 662 Bytes
Contents
# This migration comes from spree (originally 20170331121725) class AddIndexToRoleUsers < ActiveRecord::Migration[5.0] def change duplicates = Spree::RoleUser.group(:role_id, :user_id).having('sum(1) > 1').size duplicates.each do |f| role_id, user_id = f.first count = f.last - 1 # we want to leave one record roles = Spree::RoleUser.where(role_id: role_id, user_id: user_id).last(count) roles.map(&:destroy) end if index_exists? :spree_role_users, [:role_id, :user_id] remove_index :spree_role_users, [:role_id, :user_id] add_index :spree_role_users, [:role_id, :user_id], unique: true end end end
Version data entries
8 entries across 8 versions & 2 rubygems