Skip to content

Instantly share code, notes, and snippets.

@tommyip
Last active August 6, 2020 07:59
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 tommyip/81e6949d828c7ff23f861f611bb73b78 to your computer and use it in GitHub Desktop.
Save tommyip/81e6949d828c7ff23f861f611bb73b78 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Usage
# ~~~~~
#
# Run from the root of ETS
#
# $ chmod +x migrate_address
# $ ./migrate_address.rb <address csv file>
require "csv"
def migrate(address_csv)
ClientCompany.transaction do
CSV.foreach(address_csv, headers: true) do |row|
puts "Migrating #{row['ID']}"
client_company = ClientCompany.find(row["ID"])
client_company.billing_address_line_1 = row["Address 1"]
client_company.billing_address_line_2 = row["Address 2"]
client_company.billing_address_line_3 = row["Address 3"]
client_company.save
end
end
puts "Migration successful"
end
if __FILE__==$0
raise "Missing address CSV file" unless ARGV[0]
require "./config/environment"
migrate(ARGV[0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment