mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +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
|
module Legacy
|
||||||
class Contact < Db
|
class Contact < Db
|
||||||
self.table_name = :contact
|
self.table_name = :contact
|
||||||
|
belongs_to :object_registry, foreign_key: :id
|
||||||
|
belongs_to :object, foreign_key: :id
|
||||||
end
|
end
|
||||||
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
|
class AddLegacyColumnsForContact < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
add_column :contacts, :legacy_id, :integer
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -74,8 +74,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
||||||
|
|
||||||
create_table "contacts", force: :cascade do |t|
|
create_table "contacts", force: :cascade do |t|
|
||||||
t.string "code"
|
t.string "code"
|
||||||
t.string "type"
|
|
||||||
t.string "reg_no"
|
|
||||||
t.string "phone"
|
t.string "phone"
|
||||||
t.string "email"
|
t.string "email"
|
||||||
t.string "fax"
|
t.string "fax"
|
||||||
|
@ -83,8 +81,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "ident"
|
t.string "ident"
|
||||||
t.string "ident_type"
|
t.string "ident_type"
|
||||||
t.integer "created_by_id"
|
|
||||||
t.integer "updated_by_id"
|
|
||||||
t.string "auth_info"
|
t.string "auth_info"
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "org_name"
|
t.string "org_name"
|
||||||
|
@ -97,6 +93,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
||||||
t.string "zip"
|
t.string "zip"
|
||||||
t.string "country_code"
|
t.string "country_code"
|
||||||
t.string "state"
|
t.string "state"
|
||||||
|
t.integer "legacy_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree
|
add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree
|
||||||
|
|
|
@ -38,45 +38,69 @@ namespace :import do
|
||||||
puts '-----> Registrars imported'
|
puts '-----> Registrars imported'
|
||||||
end
|
end
|
||||||
|
|
||||||
# desc 'Import contacts'
|
desc 'Import contacts'
|
||||||
# task contact: :environment do
|
task contacts: :environment do
|
||||||
# puts '-----> Importing contacts...'
|
puts '-----> Importing contacts...'
|
||||||
|
|
||||||
# contacts = []
|
contacts = []
|
||||||
# existing_ids = Contact.pluck(:legacy_id)
|
existing_ids = Contact.pluck(:legacy_id)
|
||||||
|
|
||||||
# Legacy::Contact.all.each do |x|
|
# 1;"RC";"born number" # not used
|
||||||
# next if existing_ids.include?(x.id)
|
# 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"
|
ident_type_map = {
|
||||||
# 2;"OP";"identity card number" -> priv
|
2 => Contact::IDENT_PRIV,
|
||||||
# 3;"PASS";"passwport" ->
|
3 => Contact::IDENT_PASSPORT,
|
||||||
# 4;"ICO";"organization identification number"
|
4 => Contact::IDENT_TYPE_BIC,
|
||||||
# 5;"MPSV";"social system identification"
|
6 => Contact::IDENT_BIRTHDAY
|
||||||
# 6;"BIRTHDAY";"day of birth"
|
}
|
||||||
|
|
||||||
# contacts << Contact.new({
|
Legacy::Contact.all.each do |x|
|
||||||
# code: ,
|
next if existing_ids.include?(x.id)
|
||||||
# #type: , # not needed
|
begin
|
||||||
# #reg_no: x.ssn.try(:strip),
|
registrar = Registrar.find_by(legacy_id: x.object_registry.crid)
|
||||||
# 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'
|
contacts << Contact.new({
|
||||||
# end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue