mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +02:00
Map legacy contact fields to contact
This commit is contained in:
parent
a598b46723
commit
9cd4bad3a9
5 changed files with 77 additions and 40 deletions
|
@ -1,5 +1,7 @@
|
|||
module Legacy
|
||||
class Contact < Db
|
||||
self.table_name = :contact
|
||||
belongs_to :object_registry, foreign_key: :id
|
||||
belongs_to :object, foreign_key: :id
|
||||
end
|
||||
end
|
||||
|
|
10
app/models/legacy/object.rb
Normal file
10
app/models/legacy/object.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Legacy
|
||||
class Object < Db
|
||||
self.table_name = :object
|
||||
|
||||
def self.instance_method_already_implemented?(method_name)
|
||||
return true if method_name == 'update'
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,9 @@
|
|||
class AddLegacyColumnsForContact < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :contacts, :legacy_id, :integer
|
||||
remove_column :contacts, :type, :string
|
||||
remove_column :contacts, :reg_no, :string
|
||||
remove_column :contacts, :created_by_id, :integer
|
||||
remove_column :contacts, :updated_by_id, :integer
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,8 +74,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
|||
|
||||
create_table "contacts", force: :cascade do |t|
|
||||
t.string "code"
|
||||
t.string "type"
|
||||
t.string "reg_no"
|
||||
t.string "phone"
|
||||
t.string "email"
|
||||
t.string "fax"
|
||||
|
@ -83,8 +81,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
|||
t.datetime "updated_at"
|
||||
t.string "ident"
|
||||
t.string "ident_type"
|
||||
t.integer "created_by_id"
|
||||
t.integer "updated_by_id"
|
||||
t.string "auth_info"
|
||||
t.string "name"
|
||||
t.string "org_name"
|
||||
|
@ -97,6 +93,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
|||
t.string "zip"
|
||||
t.string "country_code"
|
||||
t.string "state"
|
||||
t.integer "legacy_id"
|
||||
end
|
||||
|
||||
add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree
|
||||
|
|
|
@ -38,45 +38,69 @@ namespace :import do
|
|||
puts '-----> Registrars imported'
|
||||
end
|
||||
|
||||
# desc 'Import contacts'
|
||||
# task contact: :environment do
|
||||
# puts '-----> Importing contacts...'
|
||||
desc 'Import contacts'
|
||||
task contacts: :environment do
|
||||
puts '-----> Importing contacts...'
|
||||
|
||||
# contacts = []
|
||||
# existing_ids = Contact.pluck(:legacy_id)
|
||||
contacts = []
|
||||
existing_ids = Contact.pluck(:legacy_id)
|
||||
|
||||
# Legacy::Contact.all.each do |x|
|
||||
# next if existing_ids.include?(x.id)
|
||||
# 1;"RC";"born number" # not used
|
||||
# 2;"OP";"identity card number" -> priv
|
||||
# 3;"PASS";"passwport" ->
|
||||
# 4;"ICO";"organization identification number"
|
||||
# 5;"MPSV";"social system identification" # not used
|
||||
# 6;"BIRTHDAY";"day of birth"
|
||||
|
||||
# 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"
|
||||
ident_type_map = {
|
||||
2 => Contact::IDENT_PRIV,
|
||||
3 => Contact::IDENT_PASSPORT,
|
||||
4 => Contact::IDENT_TYPE_BIC,
|
||||
6 => Contact::IDENT_BIRTHDAY
|
||||
}
|
||||
|
||||
# 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
|
||||
Legacy::Contact.all.each do |x|
|
||||
next if existing_ids.include?(x.id)
|
||||
begin
|
||||
registrar = Registrar.find_by(legacy_id: x.object_registry.crid)
|
||||
|
||||
# puts '-----> Contacts imported'
|
||||
# end
|
||||
contacts << Contact.new({
|
||||
code: x.object_registry.name,
|
||||
#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: ident_type_map[x.ssntype],
|
||||
#created_by_id: , # not needed
|
||||
#updated_by_id: , # not needed
|
||||
auth_info: x.object.authinfopw.try(:strip),
|
||||
name: x.name.try(:strip),
|
||||
org_name: x.organization.try(:strip),
|
||||
registrar_id: registrar.try(:id),
|
||||
creator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}",
|
||||
updator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}",
|
||||
ident_country_code: x.country.try(:strip),
|
||||
created_at: x.try(:crdate),
|
||||
legacy_id: x.id,
|
||||
address: Address.new({
|
||||
city: x.city.try(:strip),
|
||||
street: x.street1.try(:strip),
|
||||
zip: x.postalcode.try(:strip),
|
||||
street2: x.street2.try(:strip),
|
||||
street3: x.street3.try(:strip),
|
||||
creator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}",
|
||||
updator_str: "rake-#{`whoami`.strip} #{ARGV.join ' '}",
|
||||
country_code: x.country.try(:strip),
|
||||
state: x.stateorprovince.try(:strip)
|
||||
})
|
||||
})
|
||||
rescue => e
|
||||
binding.pry
|
||||
end
|
||||
end
|
||||
|
||||
puts '-----> Contacts imported'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue