mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 04:29:33 +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_registry, foreign_key: :id
|
||||||
belongs_to :object, foreign_key: :id
|
belongs_to :object, foreign_key: :id
|
||||||
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, -> { where('valid_to IS NULL') }, 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
|
||||||
end
|
end
|
||||||
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]
|
map[state_id]
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
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 :domains, :legacy_registrar_id, :integer
|
||||||
|
add_column :domains, :legacy_registrant_id, :integer
|
||||||
add_column :nameservers, :legacy_domain_id, :integer
|
add_column :nameservers, :legacy_domain_id, :integer
|
||||||
add_column :dnskeys, :legacy_domain_id, :integer
|
add_column :dnskeys, :legacy_domain_id, :integer
|
||||||
add_column :domain_contacts, :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
|
add_column :domain_statuses, :legacy_domain_id, :integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -162,6 +162,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
|
||||||
t.string "updator_str"
|
t.string "updator_str"
|
||||||
t.string "type"
|
t.string "type"
|
||||||
t.integer "legacy_domain_id"
|
t.integer "legacy_domain_id"
|
||||||
|
t.integer "legacy_contact_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domain_statuses", force: :cascade do |t|
|
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_dirty"
|
||||||
t.string "name_puny"
|
t.string "name_puny"
|
||||||
t.integer "period"
|
t.integer "period"
|
||||||
t.string "period_unit", limit: 1
|
t.string "period_unit", limit: 1
|
||||||
t.string "creator_str"
|
t.string "creator_str"
|
||||||
t.string "updator_str"
|
t.string "updator_str"
|
||||||
t.text "whois_body"
|
t.text "whois_body"
|
||||||
t.integer "legacy_id"
|
t.integer "legacy_id"
|
||||||
|
t.integer "legacy_registrar_id"
|
||||||
|
t.integer "legacy_registrant_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "epp_sessions", force: :cascade do |t|
|
create_table "epp_sessions", force: :cascade do |t|
|
||||||
|
|
|
@ -166,11 +166,9 @@ namespace :import do
|
||||||
|
|
||||||
domain_columns = [
|
domain_columns = [
|
||||||
"name",
|
"name",
|
||||||
"registrar_id",
|
|
||||||
"registered_at",
|
"registered_at",
|
||||||
"valid_from",
|
"valid_from",
|
||||||
"valid_to",
|
"valid_to",
|
||||||
"owner_contact_id",
|
|
||||||
"auth_info",
|
"auth_info",
|
||||||
"created_at",
|
"created_at",
|
||||||
"name_dirty",
|
"name_dirty",
|
||||||
|
@ -179,22 +177,21 @@ namespace :import do
|
||||||
"period_unit",
|
"period_unit",
|
||||||
"creator_str",
|
"creator_str",
|
||||||
"updator_str",
|
"updator_str",
|
||||||
"legacy_id"
|
"legacy_id",
|
||||||
|
"legacy_registrar_id",
|
||||||
|
"legacy_registrant_id"
|
||||||
]
|
]
|
||||||
|
|
||||||
domain_contact_columns = [
|
domain_contact_columns = [
|
||||||
"contact_id",
|
|
||||||
"domain_id",
|
|
||||||
"contact_type",
|
"contact_type",
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
"contact_code_cache",
|
|
||||||
"creator_str",
|
"creator_str",
|
||||||
"updator_str",
|
"updator_str",
|
||||||
"legacy_domain_id"
|
"legacy_domain_id",
|
||||||
|
"legacy_contact_id"
|
||||||
]
|
]
|
||||||
|
|
||||||
domain_status_columns = [
|
domain_status_columns = [
|
||||||
|
"description",
|
||||||
"value",
|
"value",
|
||||||
"creator_str",
|
"creator_str",
|
||||||
"updator_str",
|
"updator_str",
|
||||||
|
@ -222,25 +219,29 @@ namespace :import do
|
||||||
"legacy_domain_id"
|
"legacy_domain_id"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], []
|
domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], []
|
||||||
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, :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)
|
next if existing_domain_ids.include?(x.id)
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
begin
|
begin
|
||||||
domains << [
|
domains << [
|
||||||
x.object_registry.name.try(:strip),
|
x.object_registry.name.try(:strip),
|
||||||
x.object_registry.try(:registrar).try(:id),
|
|
||||||
x.object_registry.try(:crdate),
|
x.object_registry.try(:crdate),
|
||||||
x.object_registry.try(:crdate),
|
x.object_registry.try(:crdate),
|
||||||
x.exdate,
|
x.exdate,
|
||||||
x.registrant.try(:id),
|
|
||||||
x.object.authinfopw.try(:strip),
|
x.object.authinfopw.try(:strip),
|
||||||
x.object_registry.try(:crdate),
|
x.object_registry.try(:crdate),
|
||||||
x.object_registry.name.try(:strip),
|
x.object_registry.name.try(:strip),
|
||||||
|
@ -249,16 +250,27 @@ namespace :import do
|
||||||
'y',
|
'y',
|
||||||
user,
|
user,
|
||||||
user,
|
user,
|
||||||
x.id
|
x.id,
|
||||||
|
x.object_registry.try(:crid),
|
||||||
|
x.registrant
|
||||||
]
|
]
|
||||||
|
|
||||||
# domain contacts
|
# 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
|
# domain statuses
|
||||||
x.object_states.each do |state|
|
x.object_states.each do |state|
|
||||||
domain_statuses << [
|
domain_statuses << [
|
||||||
state.name.try(:strip),
|
state.desc,
|
||||||
|
state.name,
|
||||||
user,
|
user,
|
||||||
user,
|
user,
|
||||||
x.id
|
x.id
|
||||||
|
@ -266,7 +278,7 @@ namespace :import do
|
||||||
end
|
end
|
||||||
|
|
||||||
# nameservers
|
# nameservers
|
||||||
x.nsset.hosts.includes(:host_ipaddr_maps).each do |host|
|
x.nsset.hosts.each do |host|
|
||||||
ip_maps = host.host_ipaddr_maps
|
ip_maps = host.host_ipaddr_maps
|
||||||
ips = {}
|
ips = {}
|
||||||
ip_maps.each do |ip_map|
|
ip_maps.each do |ip_map|
|
||||||
|
@ -300,11 +312,11 @@ namespace :import do
|
||||||
end
|
end
|
||||||
|
|
||||||
if index % 10000 == 0 && index != 0
|
if index % 10000 == 0 && index != 0
|
||||||
puts 'importing'
|
|
||||||
Domain.import domain_columns, domains, validate: false
|
Domain.import domain_columns, domains, validate: false
|
||||||
Nameserver.import nameserver_columns, nameservers, validate: false
|
Nameserver.import nameserver_columns, nameservers, validate: false
|
||||||
Dnskey.import dnskey_columns, dnskeys, validate: false
|
Dnskey.import dnskey_columns, dnskeys, validate: false
|
||||||
DomainStatus.import domain_status_columns, domain_statuses, 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 = [], [], [], [], []
|
domains, nameservers, dnskeys, domain_statuses, domain_contacts = [], [], [], [], []
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
|
@ -316,6 +328,7 @@ namespace :import do
|
||||||
Nameserver.import nameserver_columns, nameservers, validate: false
|
Nameserver.import nameserver_columns, nameservers, validate: false
|
||||||
Dnskey.import dnskey_columns, dnskeys, validate: false
|
Dnskey.import dnskey_columns, dnskeys, validate: false
|
||||||
DomainStatus.import domain_status_columns, domain_statuses, validate: false
|
DomainStatus.import domain_status_columns, domain_statuses, validate: false
|
||||||
|
DomainContact.import domain_contact_columns, domain_contacts, validate: false
|
||||||
|
|
||||||
# puts '-----> Updating relations...'
|
# puts '-----> Updating relations...'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue