Skip to content

Instantly share code, notes, and snippets.

@jnv
Last active Apr 18, 2017
Embed
What would you like to do?
#!/usr/bin/env ruby
require 'csv-diff'
require 'pp'
file1 = ARGV[0]
file2 = ARGV[1]
IGNORE = ['created_at', 'updated_at', 'deleted_at']
COMMON_PARAMS = {
ignore_moves: true,
}
DIFF_PARAMS = {
courses: {
key_fields: 'id',
ignore_fields: IGNORE,
},
people: {
key_fields: 'id',
ignore_fields: IGNORE + ['access_token'],
},
parallels: {
key_fields: 'id',
ignore_fields: IGNORE + ['student_ids'],
},
rooms: {
key_fields: 'id',
ignore_fields: IGNORE,
},
timetable_slots: {
key_fields: 'id',
ignore_fields: IGNORE,
}
}
file_params = DIFF_PARAMS.find {|k, v| file1.include? k.to_s}
unless file_params
puts "File #{file1} does not match any key"
exit
end
file_id, file_v = file_params
params = COMMON_PARAMS.merge(file_v)
diff = CSVDiff.new(file1, file2, params)
puts '#### DELETED'
pp diff.deletes
puts '#### ADDED'
pp diff.adds
puts '#### CHANGED'
pp diff.updates
puts 'Summary'
pp diff.summary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment