Merge branch 'master' of github.com:domify/registry

This commit is contained in:
Martin Lensment 2015-04-02 18:31:05 +03:00
commit 53023b455c
33 changed files with 746 additions and 143 deletions

View file

@ -1,3 +1,7 @@
02.04.2015
* Depricated DelayedJob, kill all running delayed jobs if needed
27.03.2015
* Integrated DEPP engine to Registrar. Please note new DEPP configuration in application-example.yml

View file

@ -3,7 +3,7 @@ source 'https://rubygems.org'
# core
gem 'rails', '4.2.1'
gem 'iso8601', '~> 0.8.2' # for dates and times
gem 'hashie_rails', '~> 0.0.1'
gem 'hashie-forbidden_attributes', '~> 0.1.1'
# load env
gem 'figaro', '~> 1.1.0'
@ -16,7 +16,6 @@ gem 'paper_trail',
github: 'airblade/paper_trail',
ref: 'a453811226ec4ea59753ba6b827e390ced2fc140' # '~> 4.0.0.beta2' # archiving
gem 'rails-settings-cached', '~> 0.4.1' # for settings
gem 'delayed_job_active_record', '~> 4.0.3' # delayed job
# html-xml
gem 'haml-rails', '~> 0.9.0' # haml for views
@ -52,7 +51,6 @@ gem 'isikukood' # for EE-id validation
# deploy
gem 'whenever', '~> 0.9.4', require: false
gem 'daemons', '~> 1.1.9' # process delayed jobs
# monitors
gem 'newrelic_rpm', '~> 3.9.9.275'
@ -71,6 +69,9 @@ gem 'depp', github: 'domify/depp', ref: '800ab30dcb6dae33095bcb9df47b4e0a390891a
# gem 'depp', path: '~/projects/depp'
gem 'epp', '~> 1.4.2', github: 'gitlabeu/epp'
# for importing legacy db
gem 'activerecord-import', '~> 0.7.0' # for inserting dummy data
group :development do
# dev tools
gem 'spring', '~> 1.3.3'
@ -102,7 +103,6 @@ group :development, :test do
gem 'launchy', '~> 2.4.3' # for opening browser automatically
# helper gems
gem 'activerecord-import', '~> 0.6.0' # for inserting dummy data
gem 'database_cleaner', '~> 1.3.0' # For cleaning db in feature and epp tests
gem 'faker', '~> 1.3.0' # Library to generate fake data

View file

@ -79,7 +79,7 @@ GEM
activemodel (= 4.2.1)
activesupport (= 4.2.1)
arel (~> 6.0)
activerecord-import (0.6.0)
activerecord-import (0.7.0)
activerecord (>= 3.0)
activesupport (4.2.1)
i18n (~> 0.7)
@ -87,15 +87,15 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.6)
akami (1.2.2)
addressable (2.3.8)
akami (1.3.0)
gyoku (>= 0.4.0)
nokogiri
arel (6.0.0)
ast (2.0.0)
astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0)
autodoc (0.4.3)
autodoc (0.4.4)
actionpack
activesupport (>= 3.0.0)
rspec
@ -103,7 +103,7 @@ GEM
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.9)
bcrypt (3.1.10)
better_errors (2.0.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
@ -156,16 +156,10 @@ GEM
crack (0.4.2)
safe_yaml (~> 1.0.0)
currencies (0.4.2)
daemons (1.1.9)
database_cleaner (1.3.0)
debug_inspector (0.0.2)
deep_cloneable (2.1.1)
activerecord (>= 3.1.0, < 5.0.0)
delayed_job (4.0.6)
activesupport (>= 3.0, < 5.0)
delayed_job_active_record (4.0.3)
activerecord (>= 3.0, < 5.0)
delayed_job (>= 3.0, < 4.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (3.4.1)
@ -186,14 +180,14 @@ GEM
epp-xml (0.10.4)
activesupport (~> 4.1)
builder (~> 3.2)
equalizer (0.0.9)
equalizer (0.0.11)
erubis (2.7.0)
execjs (2.4.0)
fabrication (2.12.2)
faker (1.3.0)
i18n (~> 0.5)
fastercsv (1.5.5)
ffi (1.9.6)
ffi (1.9.8)
figaro (1.1.0)
thor (~> 0.14)
flay (2.4.0)
@ -229,7 +223,7 @@ GEM
guard-rubocop (1.1.0)
guard (~> 2.0)
rubocop (~> 0.20)
gyoku (1.2.3)
gyoku (1.3.0)
builder (>= 2.1.2)
haml (4.0.6)
tilt
@ -239,22 +233,21 @@ GEM
haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
hashie (3.3.2)
hashie_rails (0.0.1)
hashie (3.4.1)
hashie-forbidden_attributes (0.1.1)
hashie (>= 3.0)
rails (~> 4.0)
highline (1.6.21)
hike (1.2.3)
hitimes (1.2.2)
hpricot (0.8.6)
httpclient (2.6.0.1)
httpi (2.3.0)
httpi (2.4.0)
rack
i18n (0.7.0)
ice_nine (0.11.1)
isikukood (0.1.2)
iso8601 (0.8.2)
jbuilder (2.2.6)
iso8601 (0.8.5)
jbuilder (2.2.12)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (4.0.3)
@ -270,8 +263,8 @@ GEM
addressable (~> 2.3)
libv8 (3.16.14.7)
libxml-ruby (2.8.0)
listen (2.8.5)
celluloid (>= 0.15.2)
listen (2.10.0)
celluloid (~> 0.16.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
loofah (2.0.1)
@ -283,7 +276,7 @@ GEM
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.4.3)
mina (0.3.1)
mina (0.3.4)
open4 (~> 1.3.4)
rake
mini_portile (0.6.2)
@ -293,11 +286,11 @@ GEM
newrelic_rpm (3.9.9.275)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nori (2.4.0)
nprogress-rails (0.1.6.5)
nori (2.5.0)
nprogress-rails (0.1.6.6)
open4 (1.3.4)
orm_adapter (0.5.0)
parser (2.2.0.2)
parser (2.2.0.3)
ast (>= 1.1, < 3.0)
pg (0.18.1)
phantomjs (1.9.7.1)
@ -369,8 +362,8 @@ GEM
sexp_processor
ref (1.0.5)
request_store (1.1.0)
responders (2.0.2)
railties (>= 4.2.0.alpha, < 5)
responders (2.1.0)
railties (>= 4.2.0, < 5)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
@ -397,7 +390,7 @@ GEM
powerpack (~> 0.0.6)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.1)
ruby-progressbar (1.7.5)
ruby2ruby (2.1.3)
ruby_parser (~> 3.1)
sexp_processor (~> 4.0)
@ -412,13 +405,13 @@ GEM
virtus (~> 1.0)
safe_yaml (1.0.4)
sass (3.4.13)
sass-rails (5.0.1)
sass-rails (5.0.2)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
savon (2.10.1)
savon (2.11.0)
akami (~> 1.2)
builder (>= 2.1.2)
gyoku (~> 1.2)
@ -434,11 +427,11 @@ GEM
sexp_processor (4.5.0)
shoulda-matchers (2.6.2)
activesupport (>= 3.0.0)
simplecov (0.9.1)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
simplecov-html (~> 0.9.0)
simplecov-html (0.9.0)
simpleidn (0.0.5)
slim (2.1.0)
temple (~> 0.6.9)
@ -486,19 +479,19 @@ GEM
uuid (2.3.7)
macaddr (~> 1.0)
uuidtools (2.1.5)
virtus (1.0.4)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.3)
rack (>= 1.0)
wasabi (3.4.0)
wasabi (3.5.0)
httpi (~> 2.0)
nokogiri (>= 1.4.2)
websocket-driver (0.5.1)
websocket-driver (0.5.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.1)
websocket-extensions (0.1.2)
whenever (0.9.4)
chronic (>= 0.6.3)
xpath (2.0.0)
@ -508,7 +501,7 @@ PLATFORMS
ruby
DEPENDENCIES
activerecord-import (~> 0.6.0)
activerecord-import (~> 0.7.0)
autodoc
better_errors (~> 2.0.0)
binding_of_caller (~> 0.7.2)
@ -520,10 +513,8 @@ DEPENDENCIES
capybara (~> 2.4.1)
coffee-rails (~> 4.1.0)
countries (~> 0.10.0)
daemons (~> 1.1.9)
database_cleaner (~> 1.3.0)
deep_cloneable (~> 2.1.1)
delayed_job_active_record (~> 4.0.3)
depp!
devise (~> 3.4.1)
digidoc_client (~> 0.2.1)
@ -538,7 +529,7 @@ DEPENDENCIES
guard-rspec (~> 4.3.1)
guard-rubocop (~> 1.1.0)
haml-rails (~> 0.9.0)
hashie_rails (~> 0.0.1)
hashie-forbidden_attributes (~> 0.1.1)
html2haml!
isikukood
iso8601 (~> 0.8.2)

View file

@ -72,7 +72,7 @@ class Ability
can :manage, LegalDocument
can :read, ApiLog::EppLog
can :read, ApiLog::ReppLog
can :index, :delayed_job
# can :index, :delayed_job
can :create, :zonefile
can :access, :settings_menu
end

View file

@ -1,36 +1,3 @@
module DomainVersionObserver
extend ActiveSupport::Concern
# TODO: remove old
# included do
# after_save :delayed_whois_update
# end
# private
# def delayed_whois_update
# name = domain_name
# return unless name
# body = snapshot
# delay.update_private_whois(name, body)
# delay.update_public_whois(name, body)
# end
# def update_private_whois(domain_name, body)
# wd = Whois::PublicDomain.find_or_initialize_by(name: domain_name)
# wd.body = body
# wd.save!
# end
# def update_public_whois(domain_name, body)
# wd = Whois::PrivateDomain.find_or_initialize_by(name: domain_name)
# wd.body = body
# wd.save!
# end
# def domain_name
# name = reify.try(:name)
# name = load_snapshot[:domain][:name] if event == 'create'
# return name if name
# end
end

View file

@ -39,10 +39,14 @@ class Contact < ActiveRecord::Base
scope :current_registrars, ->(id) { where(registrar_id: id) }
BIC = 'bic'
PRIV = 'priv'
BIRTHDAY = 'birthday'
PASSPORT = 'passport'
IDENT_TYPES = [
BIC, # Company registry code (or similar)
'priv', # National idendtification number
'birthday' # Birthday date
BIC, # Company registry code (or similar)
PRIV, # National idendtification number
BIRTHDAY # Birthday date
]
class << self
@ -84,7 +88,7 @@ class Contact < ActiveRecord::Base
end
def to_s
name
name || '[no name]'
end
def ident_valid_format?

View file

@ -73,9 +73,9 @@ class Dnskey < ActiveRecord::Base
hex = [domain.name_in_wire_format, flags_hex, protocol_hex, alg_hex, public_key_hex].join
bin = self.class.hex_to_bin(hex)
if Setting.ds_algorithm == 1
if ds_digest_type == 1
self.ds_digest = Digest::SHA1.hexdigest(bin).upcase
elsif Setting.ds_algorithm == 2
elsif ds_digest_type == 2
self.ds_digest = Digest::SHA256.hexdigest(bin).upcase
end
end

View file

@ -236,7 +236,7 @@ class Domain < ActiveRecord::Base
# rubocop:disable Metrics/MethodLength
def update_whois_body
new_whois_body = <<-EOS
self.whois_body = <<-EOS
This Whois Server contains information on
Estonian Top Level Domain ee TLD
@ -261,11 +261,8 @@ class Domain < ActiveRecord::Base
changed: #{registrar.updated_at.to_s(:db)}
EOS
return if whois_body == new_whois_body
update_column(whois_body: new_whois_body)
update_whois_server
end
handle_asynchronously :update_whois_body
# rubocop:enable Metrics/MethodLength
def contacts_body

View file

@ -0,0 +1,8 @@
module Legacy
class Contact < Db
self.table_name = :contact
belongs_to :object_registry, foreign_key: :id
belongs_to :object, foreign_key: :id
belongs_to :object_state, foreign_key: :id, primary_key: :object_id
end
end

14
app/models/legacy/db.rb Normal file
View file

@ -0,0 +1,14 @@
module Legacy
class Db < ActiveRecord::Base
self.abstract_class = true
begin
establish_connection :fred
rescue ActiveRecord::AdapterNotSpecified => e
logger.info "'fred' database not configured, please update your database.yml file: #{e}"
end
def readonly?
true
end
end
end

View file

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

View file

@ -0,0 +1,15 @@
module Legacy
class Domain < Db
self.table_name = :domain
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'
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
has_many :nsset_contact_maps, foreign_key: :nssetid, primary_key: :nsset
end
end

View 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

View file

@ -0,0 +1,5 @@
module Legacy
class EnumObjectState < Db
self.table_name = :enum_object_states
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 Nsset < Db
self.table_name = :nsset
has_many :hosts, foreign_key: :nssetid
end
end

View file

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

View file

@ -0,0 +1,10 @@
module Legacy
class Object < Db
self.table_name = :object
def self.instance_method_already_implemented?(method_name)
return true if method_name == 'update'
super
end
end
end

View file

@ -0,0 +1,7 @@
module Legacy
class ObjectRegistry < Db
self.table_name = :object_registry
self.inheritance_column = nil
belongs_to :registrar, foreign_key: :crid, primary_key: :legacy_id, class_name: '::Registrar'
end
end

View file

@ -0,0 +1,80 @@
module Legacy
class ObjectState < Db
self.table_name = :object_state
def name
# legacy values
# 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"
# new values
map = {
2 => "serverRenewProhibited",
5 => "serverHold",
6 => "serverManualInzone",
7 => "serverBlocked",
9 => "expired",
11 => "validationWarning1",
13 => "notValidated",
14 => "nssetMissing",
15 => "serverHold",
18 => "serverRegistrantChangeProhibited",
1 => "serverDeleteProhibited",
3 => "serverTransferProhibited",
4 => "serverUpdateProhibited",
16 => "linked",
17 => "deleteCandidate", # grupistaatus
21 => "forceDelete" # grupistaatus
}
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

View file

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

View file

@ -48,7 +48,7 @@
-# %li= link_to t(:domains_history), admin_domain_versions_path
%li= link_to t(:epp_logs), admin_epp_logs_path
%li= link_to t(:repp_logs), admin_repp_logs_path
%li= link_to t(:background_jobs), admin_delayed_jobs_path
-# %li= link_to t(:background_jobs), admin_delayed_jobs_path
%li.divider
%li.dropdown-header= t('users')

View file

@ -45,8 +45,6 @@ module Registry
# Instead, the errors will propagate normally just like in other Active Record callbacks.
config.active_record.raise_in_transactional_callbacks = true
config.active_job.queue_adapter = :delayed_job
config.generators do |g|
g.stylesheets false
g.javascripts false

View file

@ -17,7 +17,6 @@ set :deploy_to, '$HOME/registry'
set :repository, 'https://github.com/domify/registry' # dev repo
set :branch, 'master'
set :rails_env, 'alpha'
set :delayed_job, true
# alpha branch
task :epp do
@ -26,7 +25,6 @@ task :epp do
set :repository, 'https://github.com/domify/registry' # dev repo
set :branch, 'master'
set :rails_env, 'alpha'
set :delayed_job, false
end
task :registrar do
@ -35,7 +33,6 @@ task :registrar do
set :repository, 'https://github.com/domify/registry' # dev repo
set :branch, 'master'
set :rails_env, 'alpha'
set :delayed_job, false
end
# staging
@ -45,7 +42,6 @@ task :st do
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master' # same as production
set :rails_env, 'staging'
set :delayed_job, true
end
# staging
@ -55,7 +51,6 @@ task :eppst do
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master' # same as production
set :rails_env, 'staging'
set :delayed_job, false
end
# staging
@ -65,7 +60,6 @@ task :registrarst do
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master'
set :rails_env, 'staging'
set :delayed_job, false
end
# production
@ -75,7 +69,6 @@ task :pr do
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master' # same as staging
set :rails_env, 'production'
set :delayed_job, true
end
# production
@ -85,7 +78,6 @@ task :epppr do
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master' # same as staging
set :rails_env, 'production'
set :delayed_job, false
end
# production
@ -95,7 +87,6 @@ task :registrarst do
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master'
set :rails_env, 'production'
set :delayed_job, false
end
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
@ -159,10 +150,6 @@ task deploy: :environment do
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
to :prepare do
invoke :'delayed_job:stop' if delayed_job
end
invoke :'git:clone'
invoke :load_commit_hash
invoke :'deploy:link_shared_paths'
@ -171,7 +158,6 @@ task deploy: :environment do
invoke :'rails:assets_precompile'
to :launch do
invoke :restart
invoke :'delayed_job:start' if delayed_job
end
end
end
@ -197,16 +183,6 @@ task load_commit_hash: :environment do
)
end
namespace :delayed_job do
task stop: :environment do
queue %(echo "-----> Stopping delayed job"; cd #{deploy_to}/current; RAILS_ENV=#{rails_env} bin/delayed_job stop)
end
task start: :environment do
queue %(echo "-----> Starting delayed job"; cd #{deploy_to}/current; RAILS_ENV=#{rails_env} bin/delayed_job start)
end
end
desc 'Restart Passenger application'
task restart: :environment do
queue "mkdir -p #{deploy_to}/current/tmp; touch #{deploy_to}/current/tmp/restart.txt"

View file

@ -0,0 +1,7 @@
class RemoveCountryIdColumns < ActiveRecord::Migration
def change
remove_column :registrars, :country_id, :integer
remove_column :users, :country_id, :integer
remove_column :addresses, :country_id, :integer
end
end

View file

@ -0,0 +1,8 @@
class AddLegacyColumnsForRegistrar < ActiveRecord::Migration
def change
add_column :registrars, :url, :string
add_column :registrars, :directo_handle, :string
add_column :registrars, :vat, :boolean
add_column :registrars, :legacy_id, :integer
end
end

View file

@ -0,0 +1,9 @@
class AddLegacyColumnsForContact < ActiveRecord::Migration
def change
add_column :contacts, :legacy_id, :integer
remove_column :contacts, :type, :string
remove_column :contacts, :reg_no, :string
remove_column :contacts, :created_by_id, :integer
remove_column :contacts, :updated_by_id, :integer
end
end

View file

@ -0,0 +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

View file

@ -0,0 +1,5 @@
class DropDelayedJob < ActiveRecord::Migration
def change
drop_table :delayed_jobs
end
end

View file

@ -11,14 +11,13 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150330083700) do
ActiveRecord::Schema.define(version: 20150402114712) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "addresses", force: :cascade do |t|
t.integer "contact_id"
t.integer "country_id"
t.string "city"
t.string "street"
t.string "zip"
@ -30,6 +29,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "updator_str"
t.string "country_code"
t.string "state"
t.integer "legacy_contact_id"
end
create_table "api_users", force: :cascade do |t|
@ -75,8 +75,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
create_table "contacts", force: :cascade do |t|
t.string "code"
t.string "type"
t.string "reg_no"
t.string "phone"
t.string "email"
t.string "fax"
@ -84,8 +82,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.datetime "updated_at"
t.string "ident"
t.string "ident_type"
t.integer "created_by_id"
t.integer "updated_by_id"
t.string "auth_info"
t.string "name"
t.string "org_name"
@ -98,6 +94,7 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "zip"
t.string "country_code"
t.string "state"
t.integer "legacy_id"
end
add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree
@ -111,22 +108,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "updator_str"
end
create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false
t.text "handler", null: false
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
create_table "delegation_signers", force: :cascade do |t|
t.integer "domain_id"
t.string "key_tag"
@ -152,6 +133,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|
@ -164,6 +146,8 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "creator_str"
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|
@ -172,6 +156,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|
@ -202,10 +187,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|
@ -573,13 +561,13 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.integer "domain_id"
t.string "creator_str"
t.string "updator_str"
t.integer "legacy_domain_id"
end
create_table "registrars", force: :cascade do |t|
t.string "name"
t.string "reg_no"
t.string "vat_no"
t.integer "country_id"
t.string "billing_address"
t.datetime "created_at"
t.datetime "updated_at"
@ -594,6 +582,10 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.string "street"
t.string "zip"
t.string "code"
t.string "url"
t.string "directo_handle"
t.boolean "vat"
t.integer "legacy_id"
end
add_index "registrars", ["code"], name: "index_registrars_on_code", using: :btree
@ -631,7 +623,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.string "identity_code"
t.integer "country_id"
t.string "roles", array: true
t.string "creator_str"
t.string "updator_str"

454
lib/tasks/import.rake Normal file
View file

@ -0,0 +1,454 @@
namespace :import do
# README
#
# 1) ESTABLISH CONNECTION TO FRED DATABASE
# ----------------------------------------
#
# Add 'fred' database connection settings to config/database.yml
# Example config:
#
# fred:
# host: localhost
# adapter: postgresql
# encoding: unicode
# pool: 5
# username: fred
# password: fred
#
# Verify you have correctly connected to fred database:
# Open Rails console:
#
# cd your_registry_deploy_path/current/
# RAILS_ENV=production bundle exec rails c
# in console: Legacy::Contact.last
# in console: exit
#
# In console you should get Last Legacy::Contact object.
# If you get any errors, scroll up and read first lines
# to figure out what went wrong to connect to fred database.
#
#
# 2) START IMPORT
# ---------------
#
# Import scrip does not write anything to fred database.
# Script is implemented this way, you can run it multiple times
# in case you need it. However already imported object are
# not reimported, thus if some object has been updated meanwhile
# in fred database, those updates will be missed and thous should
# be carried over manually. All new object in fred will be
# imported in multiple import script runs.
#
# Start all import:
#
# cd your_registry_deploy_path/current/
# RAILS_ENV=production bundle exec rails import:all
#
# If you wish to import one by one, please follow individual import order
# from task 'Import all' tasks in this script.
desc 'Import all'
task all: :environment do
Rake::Task['import:registrars'].invoke
Rake::Task['import:contacts'].invoke
Rake::Task['import:domains'].invoke
end
desc 'Import registrars'
task registrars: :environment do
start = Time.now.to_f
puts '-----> Importing registrars...'
registrars = []
existing_ids = Registrar.pluck(:legacy_id)
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
count = 0
Legacy::Registrar.all.each do |x|
next if existing_ids.include?(x.id)
count += 1
registrars << Registrar.new({
name: x.organization.try(:strip).presence || x.name.try(:strip).presence || x.handle.try(:strip).presence,
reg_no: x.ico.try(:strip),
vat_no: x.dic.try(:strip),
billing_address: nil,
phone: x.telephone.try(:strip),
email: x.email.try(:strip),
billing_email: x.billing_address.try(:strip),
country_code: x.country.try(:strip),
state: x.stateorprovince.try(:strip),
city: x.city.try(:strip),
street: x.street1.try(:strip),
zip: x.postalcode.try(:strip),
url: x.url.try(:strip),
directo_handle: x.directo_handle.try(:strip),
vat: x.vat,
legacy_id: x.id,
creator_str: user,
updator_str: user
})
end
Registrar.import registrars, validate: false
puts "-----> Imported #{count} new registrars in #{(Time.now.to_f - start).round(2)} seconds"
end
desc 'Import contacts'
task contacts: :environment do
start = Time.now.to_f
puts '-----> Importing contacts...'
# 1;"RC";"born number" # not used
# 2;"OP";"identity card number" -> priv
# 3;"PASS";"passwport" ->
# 4;"ICO";"organization identification number"
# 5;"MPSV";"social system identification" # not used
# 6;"BIRTHDAY";"day of birth"
ident_type_map = {
2 => Contact::PRIV,
3 => Contact::PASSPORT,
4 => Contact::BIC,
6 => Contact::BIRTHDAY
}
contact_columns = %w(
code
phone
email
fax
created_at
ident
ident_type
auth_info
name
org_name
registrar_id
creator_str
updator_str
ident_country_code
legacy_id
street
city
zip
state
country_code
)
contacts = []
existing_contact_ids = Contact.pluck(:legacy_id)
user = "rake-#{`whoami`.strip} #{ARGV.join ' '}"
count = 0
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)
count += 1
begin
contacts << [
x.object_registry.name.try(:strip),
x.telephone.try(:strip),
x.email.try(:strip),
x.fax.try(:strip),
x.object_registry.try(:crdate),
x.ssn.try(:strip),
ident_type_map[x.ssntype],
x.object.authinfopw.try(:strip),
x.name.try(:strip),
x.organization.try(:strip),
x.object_registry.try(:registrar).try(:id),
user,
user,
x.country.try(:strip),
x.id,
[x.street1.try(:strip), x.street2.try(:strip), x.street3.try(:strip)].join('\n'),
x.city.try(:strip),
x.postalcode.try(:strip),
x.stateorprovince.try(:strip),
x.country.try(:strip)
]
if contacts.size % 10000 == 0
Contact.import contact_columns, contacts, validate: false
contacts = []
end
rescue => e
puts "ERROR on index #{index}"
puts e
end
end
Contact.import contact_columns, contacts, validate: false
puts "-----> Imported #{count} new contacts in #{(Time.now.to_f - start).round(2)} seconds"
end
desc 'Import domains'
task domains: :environment do
start = Time.now.to_f
puts '-----> Importing domains...'
domain_columns = %w(
name
registered_at
valid_from
valid_to
auth_info
created_at
name_dirty
name_puny
period
period_unit
creator_str
updator_str
legacy_id
legacy_registrar_id
legacy_registrant_id
)
domain_contact_columns = %w(
contact_type
creator_str
updator_str
legacy_domain_id
legacy_contact_id
)
domain_status_columns = %w(
description
value
creator_str
updator_str
legacy_domain_id
)
nameserver_columns = %w(
hostname
ipv4
ipv6
creator_str
updator_str
legacy_domain_id
)
dnskey_columns = %w(
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,
: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(:crdate),
x.object_registry.try(:crdate),
x.exdate,
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,
x.object_registry.try(:crid),
x.registrant
]
# admin contacts
x.domain_contact_maps.each do |dc|
domain_contacts << [
'admin',
user,
user,
x.id,
dc.contactid
]
end
# tech contacts
x.nsset_contact_maps.each do |dc|
domain_contacts << [
'tech',
user,
user,
x.id,
dc.contactid
]
end
# domain statuses
x.object_states.each do |state|
next if state.name.blank?
domain_statuses << [
state.desc,
state.name,
user,
user,
x.id
]
end
# nameservers
x.nsset.hosts.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
x.dnskeys.each do |key|
dnskeys << [
key.flags,
key.protocol,
key.alg,
key.key,
3, # ds_alg
1, # ds_digest_type /SHA1)
user,
user,
x.id
]
end
if index % 10000 == 0 && index != 0
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
puts "ERROR on index #{index}"
puts e
end
end
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
puts '-----> Updating relations...'
# registrant
ActiveRecord::Base.connection.execute(
"UPDATE domains "\
"SET owner_contact_id = contacts.id "\
"FROM contacts "\
"WHERE contacts.legacy_id = legacy_registrant_id "\
"AND legacy_registrant_id IS NOT NULL "\
"AND owner_contact_id IS NULL"
)
# registrar
ActiveRecord::Base.connection.execute(
"UPDATE domains "\
"SET registrar_id = registrars.id "\
"FROM registrars "\
"WHERE registrars.legacy_id = legacy_registrar_id "\
"AND legacy_registrar_id IS NOT NULL "\
"AND registrar_id IS NULL"
)
# contacts
ActiveRecord::Base.connection.execute(
"UPDATE domain_contacts "\
"SET contact_id = contacts.id "\
"FROM contacts "\
"WHERE contacts.legacy_id = legacy_contact_id "\
"AND legacy_contact_id IS NOT NULL "\
"AND contact_id IS NULL"
)
ActiveRecord::Base.connection.execute(
"UPDATE domain_contacts "\
"SET domain_id = domains.id "\
"FROM domains "\
"WHERE domains.legacy_id = legacy_domain_id "\
"AND legacy_domain_id IS NOT NULL "\
"AND domain_id IS NULL"
)
# nameservers
ActiveRecord::Base.connection.execute(
"UPDATE nameservers "\
"SET domain_id = domains.id "\
"FROM domains "\
"WHERE domains.legacy_id = legacy_domain_id "\
"AND legacy_domain_id IS NOT NULL "\
"AND domain_id IS NULL"
)
# dnskeys
ActiveRecord::Base.connection.execute(
"UPDATE dnskeys "\
"SET domain_id = domains.id "\
"FROM domains "\
"WHERE domains.legacy_id = legacy_domain_id "\
"AND legacy_domain_id IS NOT NULL "\
"AND domain_id IS NULL"
)
# statuses
ActiveRecord::Base.connection.execute(
"UPDATE domain_statuses "\
"SET domain_id = domains.id "\
"FROM domains "\
"WHERE domains.legacy_id = legacy_domain_id "\
"AND legacy_domain_id IS NOT NULL "\
"AND domain_id IS NULL"
)
puts '-----> Generating dnskey digests...'
Dnskey.all.each do |x|
x.generate_digest
x.generate_ds_key_tag
x.save(validate: false)
end
puts "-----> Imported #{count} new domains in #{(Time.now.to_f - start).round(2)} seconds"
end
end

View file

@ -75,7 +75,7 @@ describe Domain do
end
it 'should not have whois_body present by default' do
@domain.whois_body.present?.should == false
@domain.whois_body.present?.should == true
end
context 'with versioning' do