WIP with contact import

This commit is contained in:
Martin Lensment 2015-02-27 12:15:28 +02:00 committed by Priit Tark
parent 3149d0731d
commit a598b46723
4 changed files with 63 additions and 3 deletions

View file

@ -0,0 +1,5 @@
module Legacy
class Contact < Db
self.table_name = :contact
end
end

View file

@ -0,0 +1,6 @@
module Legacy
class ObjectRegistry < Db
self.table_name = :object_registry
self.inheritance_column = nil
end
end

View file

@ -0,0 +1,5 @@
class AddLegacyColumnsForContact < ActiveRecord::Migration
def change
add_column :contacts, :legacy_id, :integer
end
end

View file

@ -1,9 +1,9 @@
namespace :import do
desc "Imports registrars"
desc 'Imports registrars'
task registrars: :environment do
puts '-----> Importing registrars...'
# Registrar.where('legacy_id IS NOT NULL').delete_all
Registrar.where('legacy_id IS NOT NULL').delete_all
registrars = []
existing_ids = Registrar.pluck(:legacy_id)
@ -27,7 +27,9 @@ namespace :import do
url: x.url.try(:strip),
directo_handle: x.directo_handle.try(:strip),
vat: x.vat,
legacy_id: x.id
legacy_id: x.id,
creator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}",
updator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}"
})
end
@ -35,4 +37,46 @@ namespace :import do
puts '-----> Registrars imported'
end
# desc 'Import contacts'
# task contact: :environment do
# puts '-----> Importing contacts...'
# contacts = []
# existing_ids = Contact.pluck(:legacy_id)
# Legacy::Contact.all.each do |x|
# next if existing_ids.include?(x.id)
# 1;"RC";"born number"
# 2;"OP";"identity card number" -> priv
# 3;"PASS";"passwport" ->
# 4;"ICO";"organization identification number"
# 5;"MPSV";"social system identification"
# 6;"BIRTHDAY";"day of birth"
# contacts << Contact.new({
# code: ,
# #type: , # not needed
# #reg_no: x.ssn.try(:strip),
# phone: x.telephone.try(:strip),
# email: x.email.try(:strip),
# fax: x.fax.try(:strip),
# ident: x.ssn.try(:strip),
# ident_type: ,
# #created_by_id: , # not needed
# #updated_by_id: , # not needed
# auth_info: ,
# name: x.name.try(:strip),
# org_name: x.organization.try(:strip),
# registrar_id: ,
# creator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}",
# updator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}"
# ident_country_code: x.country.try(:strip),
# legacy_id: x.id
# })
# end
# puts '-----> Contacts imported'
# end
end