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
belongs_to :object_registry, 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

View file

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

View file

@ -164,11 +164,11 @@ namespace :import do
zip
state
country_code
statuses
)
contacts = []
existing_contact_ids = Contact.pluck(:legacy_id)
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
count = 0
Legacy::Contact.includes(:object_registry, :object, object_registry: :registrar)
@ -200,7 +200,8 @@ namespace :import do
x.city.try(:strip),
x.postalcode.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