Created
May 9, 2020 19:05
-
-
Save roberthopman/9a6a380844b18e4ebe3f4e193b5336a0 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
require 'csv' | |
namespace :csv do | |
desc "generates a migration file from column names from the CSV headers" | |
task create_migration: :environment do | |
def headers_from_CSV (filename) | |
csv_header_array = CSV.read(filename, headers: true).headers | |
return csv_header_array.map { |col_a| col_a.strip.downcase.gsub(' ', '_').gsub('.', '_') } | |
end | |
file = Rails.root.join('db', 'excel_seeds.csv') | |
new_col_command = headers_from_CSV(file).join(' ') | |
if (new_col_command.length != 0) | |
sh "rails generate migration AddAttributesToPlaces #{new_col_command}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment