Import nameservers with domains

This commit is contained in:
Martin Lensment 2015-03-03 17:21:29 +02:00 committed by Priit Tark
parent 41b51455cf
commit 888d38486f
9 changed files with 73 additions and 4 deletions

View file

@ -5,6 +5,8 @@ module Legacy
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 belongs_to :object_state, foreign_key: :id, primary_key: :object_id
belongs_to :nsset, foreign_key: :nsset
belongs_to :keyset, foreign_key: :keyset
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'
end end
end end

View file

@ -0,0 +1,5 @@
module Legacy
class Dsrecord < Db
self.table_name = :dsrecord
end
end

View file

@ -0,0 +1,7 @@
module Legacy
class Host < Db
self.table_name = :host
has_many :host_ipaddr_maps, foreign_key: :hostid
end
end

View file

@ -0,0 +1,5 @@
module Legacy
class HostIpaddrMap < Db
self.table_name = :host_ipaddr_map
end
end

View file

@ -0,0 +1,7 @@
module Legacy
class Keyset < Db
self.table_name = :keyset
has_many :dsrecords, foreign_key: :keysetid
end
end

View file

@ -0,0 +1,7 @@
module Legacy
class Nsset < Db
self.table_name = :nsset
has_many :hosts, foreign_key: :nssetid
end
end

View file

@ -1,6 +1,6 @@
class AddLegacyColumnsForDomain < ActiveRecord::Migration class AddLegacyColumnsForDomain < ActiveRecord::Migration
def change def change
add_column :domains, :legacy_id, :integer add_column :domains, :legacy_id, :integer
add_column :nameservers, :legacy_id, :integer add_column :nameservers, :legacy_domain_id, :integer
end end
end end

View file

@ -570,7 +570,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.integer "domain_id" t.integer "domain_id"
t.string "creator_str" t.string "creator_str"
t.string "updator_str" t.string "updator_str"
t.integer "legacy_id" t.integer "legacy_domain_id"
end end
create_table "registrars", force: :cascade do |t| create_table "registrars", force: :cascade do |t|

View file

@ -184,12 +184,21 @@ namespace :import do
"legacy_id" "legacy_id"
] ]
nameserver_columns = [
"hostname",
"ipv4",
"ipv6",
"creator_str",
"updator_str",
"legacy_domain_id"
]
domains, nameservers = [], [] domains, nameservers = [], []
existing_domain_ids = Domain.pluck(:legacy_id) existing_domain_ids = Domain.pluck(:legacy_id)
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}" user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
count = 0 count = 0
Legacy::Domain.includes(:object_registry, :object, :registrant, :object_state, :object_registry => :registrar, :object_state => :enum_object_state).find_each(batch_size: 10000).with_index do |x, index| Legacy::Domain.includes(:object_registry, :object, :registrant, :nsset, :object_state, :object_registry => :registrar, :object_state => :enum_object_state).find_each(batch_size: 10000).with_index do |x, index|
next if existing_domain_ids.include?(x.id) next if existing_domain_ids.include?(x.id)
count += 1 count += 1
@ -213,9 +222,35 @@ namespace :import do
x.id x.id
] ]
# nameservers
x.nsset.hosts.includes(:host_ipaddr_maps).each do |host|
ip_maps = host.host_ipaddr_maps
ips = {}
ip_maps.each do |ip_map|
next unless ip_map.ipaddr
ips[:ipv4] = ip_map.ipaddr.to_s if ip_map.ipaddr.ipv4?
ips[:ipv6] = ip_map.ipaddr.to_s if ip_map.ipaddr.ipv6?
end if ip_maps.any?
nameservers << [
host.fqdn.try(:strip),
ips[:ipv4].try(:strip),
ips[:ipv6].try(:strip),
user,
user,
x.id
]
end
# dnskeys
# x.keyset.includes(:dsrecords).each do |ds|
# end
if domains.size % 10000 == 0 if domains.size % 10000 == 0
puts 'importing'
Domain.import domain_columns, domains, validate: false Domain.import domain_columns, domains, validate: false
# Address.import address_columns, addresses, validate: false Nameserver.import nameserver_columns, nameservers, validate: false
domains, nameservers = [], [] domains, nameservers = [], []
end end
rescue => e rescue => e
@ -224,6 +259,7 @@ namespace :import do
end end
Domain.import domain_columns, domains, validate: false Domain.import domain_columns, domains, validate: false
Nameserver.import nameserver_columns, nameservers, validate: false
puts "-----> Imported #{count} new domains in #{(Time.now.to_f - start).round(2)} seconds" puts "-----> Imported #{count} new domains in #{(Time.now.to_f - start).round(2)} seconds"
end end