diff --git a/lib/data_conversion/data_conversion.rb b/lib/data_conversion/base.rb similarity index 79% rename from lib/data_conversion/data_conversion.rb rename to lib/data_conversion/base.rb index ba7467d3e..0a0d70141 100644 --- a/lib/data_conversion/data_conversion.rb +++ b/lib/data_conversion/base.rb @@ -16,5 +16,13 @@ module DataConversion end Rails.logger.debug(message) if Rails.logger end + + def export_directory + "tmp/export-for-mysql" + end + + def export_path + "#{Rails.root}/#{export_directory}" + end end end \ No newline at end of file diff --git a/lib/data_conversion/export_from_mongo.rb b/lib/data_conversion/export_from_mongo.rb index fcfe483cf..2967cab5e 100644 --- a/lib/data_conversion/export_from_mongo.rb +++ b/lib/data_conversion/export_from_mongo.rb @@ -21,18 +21,10 @@ module DataConversion :force_quotes => false} end - def dirname - "export-for-mysql" - end - - def dirpath - "#{Rails.root}/#{dirname}" - end - def clear_dir - `rm -rf #{dirpath}` - `mkdir -p #{dirpath}/json` - `mkdir -p #{dirpath}/csv` + `rm -rf #{export_path}` + `mkdir -p #{export_path}/json` + `mkdir -p #{export_path}/csv` end def db_name @@ -72,10 +64,10 @@ module DataConversion log "Starting JSON export..." models.each do |model| log "Starting #{model[:name]} JSON export..." - filename ="#{dirpath}/json/#{model[:name]}.json" + filename ="#{export_path}/json/#{model[:name]}.json" model[:json_file] = filename `#{json_for_model(model[:name])} > #{filename}` - log "Completed #{model[:name]} JSON export to #{dirname}/json/#{model[:name]}.json." + log "Completed #{model[:name]} JSON export to #{export_directory}/json/#{model[:name]}.json." end log "JSON export complete." end @@ -90,7 +82,7 @@ module DataConversion log "Converting #{model_hash[:name]} json to csv" json_file = File.open(model_hash[:json_file]) - csv = CSV.open("#{dirpath}/csv/#{model_hash[:name]}.csv", 'w') + csv = CSV.open("#{export_path}/csv/#{model_hash[:name]}.csv", 'w') csv << model_hash[:attrs] json_file.each do |aspect_json| @@ -148,10 +140,10 @@ module DataConversion log "Converting #{model_hash[:name]} json to csv" json_file = File.open(model_hash[:json_file]) - people_csv = CSV.open("#{dirpath}/csv/#{model_hash[:name]}.csv", 'w') + people_csv = CSV.open("#{export_path}/csv/#{model_hash[:name]}.csv", 'w') people_csv << model_hash[:attrs] - profiles_csv = CSV.open("#{dirpath}/csv/profiles.csv", 'w') + profiles_csv = CSV.open("#{export_path}/csv/profiles.csv", 'w') profiles_csv << model_hash[:profile_attrs] json_file.each do |aspect_json| @@ -217,10 +209,10 @@ module DataConversion log "Converting #{model_hash[:name]} json to two csvs" json_file = File.open(model_hash[:json_file]) - main_csv = CSV.open("#{dirpath}/csv/#{model_hash[:name]}.csv", 'w') + main_csv = CSV.open("#{export_path}/csv/#{model_hash[:name]}.csv", 'w') main_csv << model_hash[:main_attrs] - join_csv = CSV.open("#{dirpath}/csv/#{model_hash[:join_table_name]}.csv", 'w') + join_csv = CSV.open("#{export_path}/csv/#{model_hash[:join_table_name]}.csv", 'w') join_csv << model_hash[:join_table_attrs] json_file.each do |aspect_json| diff --git a/lib/data_conversion/import_from_mysql.rb b/lib/data_conversion/import_from_mysql.rb new file mode 100644 index 000000000..d95a4c242 --- /dev/null +++ b/lib/data_conversion/import_from_mysql.rb @@ -0,0 +1,8 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +module DataConversion + class ImportToMysql < DataConversion::Base + end +end \ No newline at end of file diff --git a/spec/lib/data_conversion/import_to_mysql_spec.rb b/spec/lib/data_conversion/import_to_mysql_spec.rb new file mode 100644 index 000000000..66e74c0c0 --- /dev/null +++ b/spec/lib/data_conversion/import_to_mysql_spec.rb @@ -0,0 +1,13 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' +Dir.glob(File.join(Rails.root, 'lib', 'data_conversion', '*.rb')).each { |f| require f } + +describe DataConversion::ImportToMysql do + before do + @migrator = DataConversion::ImportToMysql.new + end + +end