mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
Import domain contacts
This commit is contained in:
parent
b11c6cbc7c
commit
0699c38584
6 changed files with 76 additions and 21 deletions
|
@ -5,9 +5,10 @@ module Legacy
|
|||
belongs_to :object_registry, foreign_key: :id
|
||||
belongs_to :object, foreign_key: :id
|
||||
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 :dnskeys, foreign_key: :keysetid, primary_key: :keyset
|
||||
has_many :domain_contact_maps, foreign_key: :domainid
|
||||
end
|
||||
end
|
||||
|
|
7
app/models/legacy/domain_contact_map.rb
Normal file
7
app/models/legacy/domain_contact_map.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
module Legacy
|
||||
class DomainContactMap < Db
|
||||
self.table_name = :domain_contact_map
|
||||
|
||||
belongs_to :contact, foreign_key: :contactid, primary_key: :legacy_id, class_name: '::Contact'
|
||||
end
|
||||
end
|
|
@ -29,5 +29,33 @@ module Legacy
|
|||
|
||||
map[state_id]
|
||||
end
|
||||
|
||||
def desc
|
||||
map = {
|
||||
1 => "Delete prohibited",
|
||||
2 => "Registration renew prohibited",
|
||||
3 => "Sponsoring registrar change prohibited",
|
||||
4 => "Update prohibited",
|
||||
7 => "Domain blocked",
|
||||
8 => "Expires within 30 days",
|
||||
9 => "Expired",
|
||||
10 => "Domain is 30 days after expiration",
|
||||
11 => "Validation of domain expire in 30 days",
|
||||
12 => "Validation of domain expire in 15 days",
|
||||
13 => "Domain not validated",
|
||||
14 => "Domain has not associated nsset",
|
||||
15 => "Domain is not generated into zone",
|
||||
16 => "Has relation to other records in registry",
|
||||
17 => "Object is going to be deleted",
|
||||
18 => "Registrant change prohibited",
|
||||
19 => "Domain will be deleted in 11 days",
|
||||
20 => "Domain is out of zone after 30 days from expiration",
|
||||
21 => "Domain is forced to delete",
|
||||
5 => "Domain is administratively kept out of zone",
|
||||
6 => "Domain is administratively kept in zone"
|
||||
}
|
||||
|
||||
map[state_id]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
class AddLegacyColumnsForDomain < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :domains, :legacy_id, :integer
|
||||
add_column :domains, :legacy_registrar_id, :integer
|
||||
add_column :domains, :legacy_registrant_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_contacts, :legacy_contact_id, :integer
|
||||
add_column :domain_statuses, :legacy_domain_id, :integer
|
||||
end
|
||||
end
|
||||
|
|
|
@ -162,6 +162,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
|||
t.string "updator_str"
|
||||
t.string "type"
|
||||
t.integer "legacy_domain_id"
|
||||
t.integer "legacy_contact_id"
|
||||
end
|
||||
|
||||
create_table "domain_statuses", force: :cascade do |t|
|
||||
|
@ -201,11 +202,13 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
|||
t.string "name_dirty"
|
||||
t.string "name_puny"
|
||||
t.integer "period"
|
||||
t.string "period_unit", limit: 1
|
||||
t.string "period_unit", limit: 1
|
||||
t.string "creator_str"
|
||||
t.string "updator_str"
|
||||
t.text "whois_body"
|
||||
t.integer "legacy_id"
|
||||
t.integer "legacy_registrar_id"
|
||||
t.integer "legacy_registrant_id"
|
||||
end
|
||||
|
||||
create_table "epp_sessions", force: :cascade do |t|
|
||||
|
|
|
@ -166,11 +166,9 @@ namespace :import do
|
|||
|
||||
domain_columns = [
|
||||
"name",
|
||||
"registrar_id",
|
||||
"registered_at",
|
||||
"valid_from",
|
||||
"valid_to",
|
||||
"owner_contact_id",
|
||||
"auth_info",
|
||||
"created_at",
|
||||
"name_dirty",
|
||||
|
@ -179,22 +177,21 @@ namespace :import do
|
|||
"period_unit",
|
||||
"creator_str",
|
||||
"updator_str",
|
||||
"legacy_id"
|
||||
"legacy_id",
|
||||
"legacy_registrar_id",
|
||||
"legacy_registrant_id"
|
||||
]
|
||||
|
||||
domain_contact_columns = [
|
||||
"contact_id",
|
||||
"domain_id",
|
||||
"contact_type",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"contact_code_cache",
|
||||
"creator_str",
|
||||
"updator_str",
|
||||
"legacy_domain_id"
|
||||
"legacy_domain_id",
|
||||
"legacy_contact_id"
|
||||
]
|
||||
|
||||
domain_status_columns = [
|
||||
"description",
|
||||
"value",
|
||||
"creator_str",
|
||||
"updator_str",
|
||||
|
@ -222,25 +219,29 @@ namespace :import do
|
|||
"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_states, :dnskeys, :object_registry => :registrar).find_each(batch_size: 10000).with_index do |x, index|
|
||||
Legacy::Domain.includes(
|
||||
:object_registry,
|
||||
:object,
|
||||
:nsset,
|
||||
:object_states,
|
||||
:dnskeys,
|
||||
:domain_contact_maps,
|
||||
:nsset => {:hosts => :host_ipaddr_maps}
|
||||
).find_each(batch_size: 10000).with_index do |x, index|
|
||||
next if existing_domain_ids.include?(x.id)
|
||||
count += 1
|
||||
|
||||
begin
|
||||
domains << [
|
||||
x.object_registry.name.try(:strip),
|
||||
x.object_registry.try(:registrar).try(:id),
|
||||
x.object_registry.try(:crdate),
|
||||
x.object_registry.try(:crdate),
|
||||
x.exdate,
|
||||
x.registrant.try(:id),
|
||||
x.object.authinfopw.try(:strip),
|
||||
x.object_registry.try(:crdate),
|
||||
x.object_registry.name.try(:strip),
|
||||
|
@ -249,16 +250,27 @@ namespace :import do
|
|||
'y',
|
||||
user,
|
||||
user,
|
||||
x.id
|
||||
x.id,
|
||||
x.object_registry.try(:crid),
|
||||
x.registrant
|
||||
]
|
||||
|
||||
# domain contacts
|
||||
|
||||
x.domain_contact_maps.each do |dc|
|
||||
domain_contacts << [
|
||||
'admin', # TODO: Where to get real contact type?
|
||||
user,
|
||||
user,
|
||||
x.id,
|
||||
dc.contactid
|
||||
]
|
||||
end
|
||||
|
||||
# domain statuses
|
||||
x.object_states.each do |state|
|
||||
domain_statuses << [
|
||||
state.name.try(:strip),
|
||||
state.desc,
|
||||
state.name,
|
||||
user,
|
||||
user,
|
||||
x.id
|
||||
|
@ -266,7 +278,7 @@ namespace :import do
|
|||
end
|
||||
|
||||
# nameservers
|
||||
x.nsset.hosts.includes(:host_ipaddr_maps).each do |host|
|
||||
x.nsset.hosts.each do |host|
|
||||
ip_maps = host.host_ipaddr_maps
|
||||
ips = {}
|
||||
ip_maps.each do |ip_map|
|
||||
|
@ -300,11 +312,11 @@ namespace :import do
|
|||
end
|
||||
|
||||
if index % 10000 == 0 && index != 0
|
||||
puts 'importing'
|
||||
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
|
||||
DomainContact.import domain_contact_columns, domain_contacts, validate: false
|
||||
domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], []
|
||||
end
|
||||
rescue => e
|
||||
|
@ -316,6 +328,7 @@ namespace :import do
|
|||
Nameserver.import nameserver_columns, nameservers, validate: false
|
||||
Dnskey.import dnskey_columns, dnskeys, validate: false
|
||||
DomainStatus.import domain_status_columns, domain_statuses, validate: false
|
||||
DomainContact.import domain_contact_columns, domain_contacts, validate: false
|
||||
|
||||
# puts '-----> Updating relations...'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue