parent
					
						
							
								a16e06bbf5
							
						
					
				
			
			
				commit
				
					
						9130b3cda9
					
				
			
		
					 1 changed files with 11 additions and 7 deletions
				
			
		|  | @ -36,7 +36,7 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] | ||||||
| 
 | 
 | ||||||
|   def deduplicate_account!(account_ids) |   def deduplicate_account!(account_ids) | ||||||
|     accounts          = Account.where(id: account_ids).to_a |     accounts          = Account.where(id: account_ids).to_a | ||||||
|     accounts          = account.first.local? ? accounts.sort_by(&:created_at) : accounts.sort_by(&:updated_at).reverse |     accounts          = accounts.first.local? ? accounts.sort_by(&:created_at) : accounts.sort_by(&:updated_at).reverse | ||||||
|     reference_account = accounts.shift |     reference_account = accounts.shift | ||||||
| 
 | 
 | ||||||
|     accounts.each do |other_account| |     accounts.each do |other_account| | ||||||
|  | @ -69,12 +69,15 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] | ||||||
|     # to check for (and skip past) uniqueness errors |     # to check for (and skip past) uniqueness errors | ||||||
|     [Follow, FollowRequest, Block, Mute].each do |klass| |     [Follow, FollowRequest, Block, Mute].each do |klass| | ||||||
|       klass.where(account_id: duplicate_account.id).find_each do |record| |       klass.where(account_id: duplicate_account.id).find_each do |record| | ||||||
|  |         begin | ||||||
|           record.update(account_id: main_account.id) |           record.update(account_id: main_account.id) | ||||||
|         rescue ActiveRecord::RecordNotUnique |         rescue ActiveRecord::RecordNotUnique | ||||||
|           next |           next | ||||||
|         end |         end | ||||||
|  |       end | ||||||
| 
 | 
 | ||||||
|       klass.where(target_account_id: duplicate_account.id).find_each do |record| |       klass.where(target_account_id: duplicate_account.id).find_each do |record| | ||||||
|  |         begin | ||||||
|           record.update(target_account_id: main_account.id) |           record.update(target_account_id: main_account.id) | ||||||
|         rescue ActiveRecord::RecordNotUnique |         rescue ActiveRecord::RecordNotUnique | ||||||
|           next |           next | ||||||
|  | @ -82,3 +85,4 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  | end | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue