Domain statuses import

This commit is contained in:
Martin Lensment 2015-03-04 13:37:20 +02:00 committed by Priit Tark
parent 888d38486f
commit b11c6cbc7c
8 changed files with 111 additions and 27 deletions

View file

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

View file

@ -4,9 +4,10 @@ module Legacy
belongs_to :object_registry, foreign_key: :id
belongs_to :object, foreign_key: :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'
has_many :object_states, -> { where('valid_to IS NULL') }, foreign_key: :object_id
has_many :dnskeys, foreign_key: :keysetid, primary_key: :keyset
end
end

View file

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

View file

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

View file

@ -2,8 +2,32 @@ module Legacy
class ObjectState < Db
self.table_name = :object_state
belongs_to :enum_object_state, foreign_key: :state_id
def name
map = {
2 => "serverRenewProhibited",
5 => "serverOutzoneManual",
6 => "serverInzoneManual",
7 => "serverBlocked",
8 => "expirationWarning",
9 => "expired",
10 => "unguarded",
11 => "validationWarning1",
12 => "validationWarning2",
13 => "notValidated",
14 => "nssetMissing",
15 => "outzone",
18 => "serverRegistrantChangeProhibited",
19 => "deleteWarning",
20 => "outzoneUnguarded",
1 => "serverDeleteProhibited",
3 => "serverTransferProhibited",
4 => "serverUpdateProhibited",
16 => "linked",
17 => "deleteCandidate",
21 => "forceDelete"
}
delegate :name, to: :enum_object_state, prefix: false, allow_nil: true
map[state_id]
end
end
end

View file

@ -2,5 +2,8 @@ class AddLegacyColumnsForDomain < ActiveRecord::Migration
def change
add_column :domains, :legacy_id, :integer
add_column :nameservers, :legacy_domain_id, :integer
add_column :dnskeys, :legacy_domain_id, :integer
add_column :domain_contacts, :legacy_domain_id, :integer
add_column :domain_statuses, :legacy_domain_id, :integer
end
end

View file

@ -148,6 +148,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "ds_digest"
t.string "creator_str"
t.string "updator_str"
t.integer "legacy_domain_id"
end
create_table "domain_contacts", force: :cascade do |t|
@ -160,6 +161,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "creator_str"
t.string "updator_str"
t.string "type"
t.integer "legacy_domain_id"
end
create_table "domain_statuses", force: :cascade do |t|
@ -168,6 +170,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "value"
t.string "creator_str"
t.string "updator_str"
t.integer "legacy_domain_id"
end
create_table "domain_transfers", force: :cascade do |t|

View file

@ -164,12 +164,10 @@ namespace :import do
start = Time.now.to_f
puts '-----> Importing domains...'
domain_columns = [
"name",
"registrar_id",
"registered_at",
"status",
"valid_from",
"valid_to",
"owner_contact_id",
@ -184,6 +182,25 @@ namespace :import do
"legacy_id"
]
domain_contact_columns = [
"contact_id",
"domain_id",
"contact_type",
"created_at",
"updated_at",
"contact_code_cache",
"creator_str",
"updator_str",
"legacy_domain_id"
]
domain_status_columns = [
"value",
"creator_str",
"updator_str",
"legacy_domain_id"
]
nameserver_columns = [
"hostname",
"ipv4",
@ -193,12 +210,26 @@ namespace :import do
"legacy_domain_id"
]
domains, nameservers = [], []
dnskey_columns = [
"flags",
"protocol",
"alg",
"public_key",
"ds_alg",
"ds_digest_type",
"creator_str",
"updator_str",
"legacy_domain_id"
]
domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], []
existing_domain_ids = Domain.pluck(:legacy_id)
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
count = 0
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|
Legacy::Domain.includes(:object_registry, :object, :registrant, :nsset, :object_states, :dnskeys, :object_registry => :registrar).find_each(batch_size: 10000).with_index do |x, index|
next if existing_domain_ids.include?(x.id)
count += 1
@ -207,7 +238,6 @@ namespace :import do
x.object_registry.name.try(:strip),
x.object_registry.try(:registrar).try(:id),
x.object_registry.try(:crdate),
x.object_state.try(:name).try(:strip),
x.object_registry.try(:crdate),
x.exdate,
x.registrant.try(:id),
@ -222,6 +252,19 @@ namespace :import do
x.id
]
# domain contacts
# domain statuses
x.object_states.each do |state|
domain_statuses << [
state.name.try(:strip),
user,
user,
x.id
]
end
# nameservers
x.nsset.hosts.includes(:host_ipaddr_maps).each do |host|
ip_maps = host.host_ipaddr_maps
@ -242,16 +285,27 @@ namespace :import do
]
end
# dnskeys
# x.keyset.includes(:dsrecords).each do |ds|
x.dnskeys.each do |key|
dnskeys << [
key.flags,
key.protocol,
key.alg,
key.key,
3, # ds_alg
Setting.ds_algorithm, # ds_digest_type
user,
user,
x.id
]
end
# end
if domains.size % 10000 == 0
if index % 10000 == 0 && index != 0
puts 'importing'
Domain.import domain_columns, domains, validate: false
Nameserver.import nameserver_columns, nameservers, validate: false
domains, nameservers = [], []
Dnskey.import dnskey_columns, dnskeys, validate: false
DomainStatus.import domain_status_columns, domain_statuses, validate: false
domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], []
end
rescue => e
binding.pry
@ -260,6 +314,12 @@ namespace :import do
Domain.import domain_columns, domains, validate: false
Nameserver.import nameserver_columns, nameservers, validate: false
Dnskey.import dnskey_columns, dnskeys, validate: false
DomainStatus.import domain_status_columns, domain_statuses, validate: false
# puts '-----> Updating relations...'
# puts '-----> Generating dnskey digests...'
puts "-----> Imported #{count} new domains in #{(Time.now.to_f - start).round(2)} seconds"
end