Last active
August 6, 2020 07:59
-
-
Save tommyip/81e6949d828c7ff23f861f611bb73b78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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