diff --git a/app/models/legacy/domain_contact_map_history.rb b/app/models/legacy/domain_contact_map_history.rb new file mode 100644 index 000000000..9ad3a6f7e --- /dev/null +++ b/app/models/legacy/domain_contact_map_history.rb @@ -0,0 +1,5 @@ +module Legacy + class DomainContactMapHistory < Db + self.table_name = :domain_contact_map_history + end +end diff --git a/app/models/legacy/domain_history.rb b/app/models/legacy/domain_history.rb index 467c470b9..7a81db413 100644 --- a/app/models/legacy/domain_history.rb +++ b/app/models/legacy/domain_history.rb @@ -8,13 +8,14 @@ module Legacy belongs_to :domain, foreign_key: :id belongs_to :history, foreign_key: :historyid has_one :object_history, foreign_key: :historyid, primary_key: :historyid + has_many :domain_contact_map_histories, foreign_key: :historyid, primary_key: :historyid def get_current_domain_object(time, change_param) x = self { name: SimpleIDN.to_unicode(x.object_registry.name.try(:strip)), registrar_id: ::Registrar.find_by(legacy_id: x.object_history.try(:clid)).try(:id), - registrant_id: ::Contact.find_by(legacy_id: x.registrant).try(:id), + registrant_id: new_registrant_id, registered_at: x.object_registry.try(:crdate), valid_from: x.object_registry.try(:crdate), valid_to: x.exdate, @@ -34,6 +35,15 @@ module Legacy } end + def get_admin_contact_new_ids + c_ids = domain_contact_map_histories.pluck(:contactid).join("','") + DomainVersion.where("object->>'legacy_id' IN ('#{c_ids}')").uniq.pluck(:item_id) + end + + def new_registrant_id + @new_registrant_id ||= ::Contact.find_by(legacy_id: registrant).try(:id) + end + class << self def changes_dates_for domain_id sql = %Q{SELECT dh.*, valid_from diff --git a/lib/tasks/import_history.rake b/lib/tasks/import_history.rake index 4f3a79e0f..bf12e3e18 100644 --- a/lib/tasks/import_history.rake +++ b/lib/tasks/import_history.rake @@ -129,7 +129,12 @@ namespace :import do object: last_changes, object_changes: changes, created_at: time, - children: {} + children: { + admin_contacts: [responder.get_admin_contact_new_ids], + tech_contacts: [], + nameservers: [], + registrant: [responder.new_registrant_id] + } ) last_changes = new_attrs