Skip to content

Instantly share code, notes, and snippets.

@jnv
Last active April 18, 2017 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnv/46458f87ffb2c1c992be9df7c5590302 to your computer and use it in GitHub Desktop.
Save jnv/46458f87ffb2c1c992be9df7c5590302 to your computer and use it in GitHub Desktop.
#!/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