Skip to content

Commit

Permalink
Keep latest duplicate instead of the oldest duplicate
Browse files Browse the repository at this point in the history
Keep latest duplicate instead of the oldest duplicate
  • Loading branch information
Ladas committed Nov 14, 2017
1 parent 0ba6661 commit ffd2027
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Container < ActiveRecord::Base
end

def duplicate_data_query_returning_min_id(model, unique_index_columns)
model.group(unique_index_columns).select("min(id)")
model.group(unique_index_columns).select("max(id)")
end

def cleanup_duplicate_data_delete_all(model, unique_index_columns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build_value(key, foreign_key_value, string_value)
def analyze(model)
original_values = {}
duplicate_values = {}
model.all.each do |record|
model.order("id DESC").all.each do |record|
index = record.attributes.symbolize_keys.slice(*model_unique_keys(model))
if original_values[index]
duplicate_values[index] << record.id
Expand All @@ -64,9 +64,9 @@ def assert_before_migration_test_data(model, original_values, duplicate_values)
expect(original_values.count).to eq(original_values_count(model))
expect(duplicate_values.values.flatten.count).to eq(duplicate_values_count(model))

# Check that original values ids are the min or all duplicated ids
# Check that original values ids are the max or all duplicated ids
original_values.each do |key, value|
expect((duplicate_values[key] << value).min).to eq value
expect((duplicate_values[key] << value).max).to eq value
end
end

Expand Down

0 comments on commit ffd2027

Please sign in to comment.