mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Basic domain import
This commit is contained in:
parent
7707f5ff8e
commit
41b51455cf
7 changed files with 107 additions and 10 deletions
|
@ -3,5 +3,6 @@ module Legacy
|
||||||
self.table_name = :contact
|
self.table_name = :contact
|
||||||
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
10
app/models/legacy/domain.rb
Normal file
10
app/models/legacy/domain.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
module Legacy
|
||||||
|
class Domain < Db
|
||||||
|
self.table_name = :domain
|
||||||
|
|
||||||
|
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 :registrant, foreign_key: :registrant, primary_key: :legacy_id, class_name: '::Contact'
|
||||||
|
end
|
||||||
|
end
|
5
app/models/legacy/enum_object_state.rb
Normal file
5
app/models/legacy/enum_object_state.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module Legacy
|
||||||
|
class EnumObjectState < Db
|
||||||
|
self.table_name = :enum_object_states
|
||||||
|
end
|
||||||
|
end
|
9
app/models/legacy/object_state.rb
Normal file
9
app/models/legacy/object_state.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module Legacy
|
||||||
|
class ObjectState < Db
|
||||||
|
self.table_name = :object_state
|
||||||
|
|
||||||
|
belongs_to :enum_object_state, foreign_key: :state_id
|
||||||
|
|
||||||
|
delegate :name, to: :enum_object_state, prefix: false, allow_nil: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddLegacyColumnsForDomain < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :domains, :legacy_id, :integer
|
||||||
|
add_column :nameservers, :legacy_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,12 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
ActiveRecord::Schema.define(version: 20150330083700) do
|
ActiveRecord::Schema.define(version: 20150330083700) do
|
||||||
=======
|
|
||||||
ActiveRecord::Schema.define(version: 20150302130224) do
|
|
||||||
>>>>>>> Contact importing
|
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
@ -207,6 +202,7 @@ ActiveRecord::Schema.define(version: 20150302130224) do
|
||||||
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"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "epp_sessions", force: :cascade do |t|
|
create_table "epp_sessions", force: :cascade do |t|
|
||||||
|
@ -574,6 +570,7 @@ ActiveRecord::Schema.define(version: 20150302130224) 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"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "registrars", force: :cascade do |t|
|
create_table "registrars", force: :cascade do |t|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
namespace :import do
|
namespace :import do
|
||||||
desc 'Imports registrars'
|
desc 'Import registrars'
|
||||||
task registrars: :environment do
|
task registrars: :environment do
|
||||||
start = Time.now.to_f
|
start = Time.now.to_f
|
||||||
puts '-----> Importing registrars...'
|
puts '-----> Importing registrars...'
|
||||||
|
@ -81,6 +81,7 @@ namespace :import do
|
||||||
"city",
|
"city",
|
||||||
"street",
|
"street",
|
||||||
"zip",
|
"zip",
|
||||||
|
"created_at",
|
||||||
"street2",
|
"street2",
|
||||||
"street3",
|
"street3",
|
||||||
"creator_str",
|
"creator_str",
|
||||||
|
@ -92,22 +93,20 @@ namespace :import do
|
||||||
|
|
||||||
contacts, addresses = [], []
|
contacts, addresses = [], []
|
||||||
existing_contact_ids = Contact.pluck(:legacy_id)
|
existing_contact_ids = Contact.pluck(:legacy_id)
|
||||||
existing_address_ids = Address.pluck(:legacy_contact_id)
|
|
||||||
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
|
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
Legacy::Contact.includes(:object_registry, :object, :object_registry => :registrar).find_each(batch_size: 10000).with_index do |x, index|
|
Legacy::Contact.includes(:object_registry, :object, :object_registry => :registrar).find_each(batch_size: 10000).with_index do |x, index|
|
||||||
next if existing_contact_ids.include?(x.id)
|
next if existing_contact_ids.include?(x.id)
|
||||||
next if existing_address_ids.include?(x.id)
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
begin
|
begin
|
||||||
contacts << [
|
contacts << [
|
||||||
x.object_registry.name,
|
x.object_registry.name.try(:strip),
|
||||||
x.telephone.try(:strip),
|
x.telephone.try(:strip),
|
||||||
x.email.try(:strip),
|
x.email.try(:strip),
|
||||||
x.fax.try(:strip),
|
x.fax.try(:strip),
|
||||||
x.try(:crdate),
|
x.object_registry.try(:crdate),
|
||||||
x.ssn.try(:strip),
|
x.ssn.try(:strip),
|
||||||
ident_type_map[x.ssntype],
|
ident_type_map[x.ssntype],
|
||||||
x.object.authinfopw.try(:strip),
|
x.object.authinfopw.try(:strip),
|
||||||
|
@ -124,6 +123,7 @@ namespace :import do
|
||||||
x.city.try(:strip),
|
x.city.try(:strip),
|
||||||
x.street1.try(:strip),
|
x.street1.try(:strip),
|
||||||
x.postalcode.try(:strip),
|
x.postalcode.try(:strip),
|
||||||
|
x.object_registry.try(:crdate),
|
||||||
x.street2.try(:strip),
|
x.street2.try(:strip),
|
||||||
x.street3.try(:strip),
|
x.street3.try(:strip),
|
||||||
user,
|
user,
|
||||||
|
@ -158,4 +158,73 @@ namespace :import do
|
||||||
)
|
)
|
||||||
puts "-----> Imported #{count} new contacts in #{(Time.now.to_f - start).round(2)} seconds"
|
puts "-----> Imported #{count} new contacts in #{(Time.now.to_f - start).round(2)} seconds"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Import domains'
|
||||||
|
task domains: :environment do
|
||||||
|
start = Time.now.to_f
|
||||||
|
puts '-----> Importing domains...'
|
||||||
|
|
||||||
|
|
||||||
|
domain_columns = [
|
||||||
|
"name",
|
||||||
|
"registrar_id",
|
||||||
|
"registered_at",
|
||||||
|
"status",
|
||||||
|
"valid_from",
|
||||||
|
"valid_to",
|
||||||
|
"owner_contact_id",
|
||||||
|
"auth_info",
|
||||||
|
"created_at",
|
||||||
|
"name_dirty",
|
||||||
|
"name_puny",
|
||||||
|
"period",
|
||||||
|
"period_unit",
|
||||||
|
"creator_str",
|
||||||
|
"updator_str",
|
||||||
|
"legacy_id"
|
||||||
|
]
|
||||||
|
|
||||||
|
domains, nameservers = [], []
|
||||||
|
existing_domain_ids = Domain.pluck(:legacy_id)
|
||||||
|
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
|
||||||
|
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|
|
||||||
|
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_state.try(:name).try(:strip),
|
||||||
|
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),
|
||||||
|
SimpleIDN.to_ascii(x.object_registry.name.try(:strip)),
|
||||||
|
1,
|
||||||
|
'y',
|
||||||
|
user,
|
||||||
|
user,
|
||||||
|
x.id
|
||||||
|
]
|
||||||
|
|
||||||
|
if domains.size % 10000 == 0
|
||||||
|
Domain.import domain_columns, domains, validate: false
|
||||||
|
# Address.import address_columns, addresses, validate: false
|
||||||
|
domains, nameservers = [], []
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
binding.pry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Domain.import domain_columns, domains, validate: false
|
||||||
|
|
||||||
|
puts "-----> Imported #{count} new domains in #{(Time.now.to_f - start).round(2)} seconds"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue