in the migration script add state to the Contact

This commit is contained in:
Vladimir Krylov 2015-10-29 15:22:03 +02:00
parent 736aff0fc8
commit d2b5266887
3 changed files with 33 additions and 30 deletions

View file

@ -3,6 +3,7 @@ module Legacy
self.table_name = :contact self.table_name = :contact
belongs_to :object_registry, foreign_key: :id belongs_to :object_registry, foreign_key: :id
belongs_to :object, foreign_key: :id belongs_to :object, foreign_key: :id
belongs_to :object_state, foreign_key: :id, primary_key: :object_id
has_one :object_state, -> { where('valid_to IS NULL') }, foreign_key: :object_id
end end
end end

View file

@ -2,7 +2,6 @@ module Legacy
class ObjectState < Db class ObjectState < Db
self.table_name = :object_state self.table_name = :object_state
def name
# legacy values # legacy values
# 2 => "serverRenewProhibited", # 2 => "serverRenewProhibited",
# 5 => "serverOutzoneManual", # 5 => "serverOutzoneManual",
@ -27,7 +26,7 @@ module Legacy
# 21 => "forceDelete" # 21 => "forceDelete"
# new values # new values
map = { STATE_NAMES = {
2 => "serverRenewProhibited", 2 => "serverRenewProhibited",
5 => "serverHold", 5 => "serverHold",
6 => "serverManualInzone", 6 => "serverManualInzone",
@ -44,9 +43,11 @@ module Legacy
16 => "linked", 16 => "linked",
17 => "deleteCandidate", # grupistaatus 17 => "deleteCandidate", # grupistaatus
21 => "forceDelete" # grupistaatus 21 => "forceDelete" # grupistaatus
} }.freeze
map[state_id]
def name
STATE_NAMES[state_id]
end end
def desc def desc

View file

@ -164,11 +164,11 @@ namespace :import do
zip zip
state state
country_code country_code
statuses
) )
contacts = [] contacts = []
existing_contact_ids = Contact.pluck(:legacy_id) existing_contact_ids = Contact.pluck(:legacy_id)
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
count = 0 count = 0
Legacy::Contact.includes(:object_registry, :object, object_registry: :registrar) Legacy::Contact.includes(:object_registry, :object, object_registry: :registrar)
@ -200,7 +200,8 @@ namespace :import do
x.city.try(:strip), x.city.try(:strip),
x.postalcode.try(:strip), x.postalcode.try(:strip),
x.stateorprovince.try(:strip), x.stateorprovince.try(:strip),
x.country.try(:strip) x.country.try(:strip),
[x.object_state.try(:name)|| Contact::OK]
] ]
if contacts.size % 10000 == 0 if contacts.size % 10000 == 0