mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 12:39:34 +02:00
Story#104525318 - cleanup import code
This commit is contained in:
parent
e11c1b5d20
commit
3c0e04beac
3 changed files with 35 additions and 23 deletions
|
@ -7,11 +7,23 @@ module Legacy
|
||||||
belongs_to :nsset, foreign_key: :nsset
|
belongs_to :nsset, foreign_key: :nsset
|
||||||
# belongs_to :registrant, foreign_key: :registrant, primary_key: :legacy_id, class_name: '::Contact'
|
# belongs_to :registrant, foreign_key: :registrant, primary_key: :legacy_id, class_name: '::Contact'
|
||||||
|
|
||||||
has_many :object_states, -> { where('valid_to IS NULL') }, foreign_key: :object_id
|
has_many :object_states, foreign_key: :object_id
|
||||||
has_many :dnskeys, foreign_key: :keysetid, primary_key: :keyset
|
has_many :dnskeys, foreign_key: :keysetid, primary_key: :keyset
|
||||||
has_many :domain_contact_maps, foreign_key: :domainid
|
has_many :domain_contact_maps, foreign_key: :domainid
|
||||||
has_many :nsset_contact_maps, foreign_key: :nssetid, primary_key: :nsset
|
has_many :nsset_contact_maps, foreign_key: :nssetid, primary_key: :nsset
|
||||||
has_many :domain_histories, foreign_key: :id
|
has_many :domain_histories, foreign_key: :id
|
||||||
alias_method :history, :domain_histories
|
alias_method :history, :domain_histories
|
||||||
|
|
||||||
|
|
||||||
|
def new_states
|
||||||
|
domain_statuses = []
|
||||||
|
object_states.valid.each do |state|
|
||||||
|
next if state.name.blank?
|
||||||
|
domain_statuses << state.name
|
||||||
|
end
|
||||||
|
|
||||||
|
# OK status is default
|
||||||
|
domain_statuses << DomainStatus::OK if domain_statuses.empty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,8 @@ module Legacy
|
||||||
class ObjectState < Db
|
class ObjectState < Db
|
||||||
self.table_name = :object_state
|
self.table_name = :object_state
|
||||||
|
|
||||||
|
scope :valid, -> { where('valid_to IS NULL') }
|
||||||
|
|
||||||
# legacy values. Just for log
|
# legacy values. Just for log
|
||||||
# 2 => "serverRenewProhibited",
|
# 2 => "serverRenewProhibited",
|
||||||
# 5 => "serverOutzoneManual",
|
# 5 => "serverOutzoneManual",
|
||||||
|
|
|
@ -364,16 +364,6 @@ namespace :import do
|
||||||
legacy_contact_id
|
legacy_contact_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# rubocop: disable Lint/UselessAssignment
|
|
||||||
domain_status_columns = %w(
|
|
||||||
description
|
|
||||||
value
|
|
||||||
creator_str
|
|
||||||
updator_str
|
|
||||||
legacy_domain_id
|
|
||||||
)
|
|
||||||
# rubocop: enable Lint/UselessAssignment
|
|
||||||
|
|
||||||
nameserver_columns = %w(
|
nameserver_columns = %w(
|
||||||
hostname
|
hostname
|
||||||
ipv4
|
ipv4
|
||||||
|
@ -398,7 +388,6 @@ namespace :import do
|
||||||
|
|
||||||
domains, nameservers, dnskeys, domain_contacts = [], [], [], []
|
domains, nameservers, dnskeys, domain_contacts = [], [], [], []
|
||||||
existing_domain_ids = Domain.pluck(:legacy_id)
|
existing_domain_ids = Domain.pluck(:legacy_id)
|
||||||
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
Legacy::Domain.includes(
|
Legacy::Domain.includes(
|
||||||
|
@ -414,16 +403,6 @@ namespace :import do
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# domain statuses
|
|
||||||
domain_statuses = []
|
|
||||||
x.object_states.each do |state|
|
|
||||||
next if state.name.blank?
|
|
||||||
domain_statuses << state.name
|
|
||||||
end
|
|
||||||
|
|
||||||
# OK status is default
|
|
||||||
domain_statuses << DomainStatus::OK if domain_statuses.empty?
|
|
||||||
|
|
||||||
domains << [
|
domains << [
|
||||||
x.object_registry.name.try(:strip),
|
x.object_registry.name.try(:strip),
|
||||||
Registrar.find_by(legacy_id: x.object.try(:clid)).try(:id),
|
Registrar.find_by(legacy_id: x.object.try(:clid)).try(:id),
|
||||||
|
@ -442,7 +421,7 @@ namespace :import do
|
||||||
x.id,
|
x.id,
|
||||||
x.object_registry.try(:crid),
|
x.object_registry.try(:crid),
|
||||||
x.registrant,
|
x.registrant,
|
||||||
domain_statuses
|
x.new_states
|
||||||
]
|
]
|
||||||
|
|
||||||
# admin contacts
|
# admin contacts
|
||||||
|
@ -777,6 +756,25 @@ namespace :import do
|
||||||
|
|
||||||
desc 'Import history'
|
desc 'Import history'
|
||||||
task history: :environment do
|
task history: :environment do
|
||||||
|
# {"id"=>83215, "name"=>"gssb-dsf0pf.ee", "registrar_id"=>17,
|
||||||
|
# "registered_at"=>Thu, 18 Sep 2014 10:17:13 EEST +03:00,
|
||||||
|
# "status"=>nil, "valid_from"=>Thu, 18 Sep 2014 10:17:13 EEST +03:00,
|
||||||
|
# "valid_to"=>Fri, 18 Sep 2015 00:00:00 EEST +03:00, "registrant_id"=>262841,
|
||||||
|
# "auth_info"=>"authinfopw", "created_at"=>Thu, 18 Sep 2014 10:17:13 EEST +03:00,
|
||||||
|
# "updated_at"=>Thu, 18 Sep 2014 10:17:13 EEST +03:00, "name_dirty"=>"gssb-dsf0pf.ee",
|
||||||
|
# "name_puny"=>"gssb-dsf0pf.ee", "period"=>1, "period_unit"=>"y", "creator_str"=>"Elkdata OÜ",
|
||||||
|
# "updator_str"=>"Elkdata OÜ", "legacy_id"=>778106, "legacy_registrar_id"=>13, "legacy_registrant_id"=>778104,
|
||||||
|
# "outzone_at"=>nil, "delete_at"=>nil, "registrant_verification_asked_at"=>nil,
|
||||||
|
# "registrant_verification_token"=>nil,
|
||||||
|
# "pending_json"=>{}, "force_delete_at"=>nil, "statuses"=>["ok"],
|
||||||
|
# "reserved"=>false, "status_notes"=>{}, "statuses_backup"=>[]}
|
||||||
|
|
||||||
|
Legacy::DomainHistory.uniq.pluck(:id).each do |legacy_domain_id|
|
||||||
|
# 1. add domain changes
|
||||||
|
# 2. add states
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
Domain.where.not(legacy_id: nil).find_each do |domain|
|
Domain.where.not(legacy_id: nil).find_each do |domain|
|
||||||
next if domain.versions.where(action: :create).any?
|
next if domain.versions.where(action: :create).any?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue