-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,6 @@ | |
/node_modules | ||
coverage | ||
.DS_Store | ||
|
||
# Ignore import files directory for data from old app | ||
/import_files |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace :import_data do | ||
# Import data from the old app from CSV files | ||
# Files will be located in the import_files directory | ||
# Files will not be committed to the repository | ||
require "csv" | ||
|
||
# This is a starting point for the import process | ||
# We will refactor for elegance | ||
|
||
desc "Import Providers and Associate With Regions" | ||
task providers: :environment do | ||
file_path = Rails.root.join("import_files", "Providers.csv") | ||
data = CSV.read(file_path, headers: true) | ||
data.each do |row| | ||
provider = Provider.find_or_create_by!(name: row["Provider_Name"], provider_type: row["Provider_Type"]) | ||
region = Region.find_or_create_by!(name: row["region_name"]) | ||
# TODO: we need the association table | ||
# Associate the provider with the region if it is not already associated | ||
# unless provider.regions.include?(region) | ||
# provider.regions << region | ||
# end | ||
puts "Provider #{provider.name} associated with region #{region.name}" | ||
|
||
user = User.find_or_create_by!(email_address: "#{row["Provider_Name"].underscore.downcase}@update.me", password_digest: BCrypt::Password.create(row["Provider_Password"]), is_admin: false) | ||
# TODO: add provider_id once that association is in place | ||
puts "User #{user.email_address} created" | ||
end | ||
end | ||
end |