mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 10:19:45 +02:00
Story#108521790 Domain historical attributes attributes at particular moment
This commit is contained in:
parent
f5a3e51e69
commit
beee0a0ad8
3 changed files with 27 additions and 15 deletions
|
@ -9,11 +9,11 @@ module Legacy
|
||||||
belongs_to :history, foreign_key: :historyid
|
belongs_to :history, foreign_key: :historyid
|
||||||
has_one :object_history, foreign_key: :historyid, primary_key: :historyid
|
has_one :object_history, foreign_key: :historyid, primary_key: :historyid
|
||||||
|
|
||||||
def get_current_domain_object(change_param)
|
def get_current_domain_object(time, change_param)
|
||||||
x = self
|
x = self
|
||||||
{
|
{
|
||||||
name: SimpleIDN.to_unicode(x.object_registry.name.try(:strip)),
|
name: SimpleIDN.to_unicode(x.object_registry.name.try(:strip)),
|
||||||
registrar_id: Registrar.find_by(legacy_id: x.object.try(:clid)).try(:id),
|
registrar_id: ::Registrar.find_by(legacy_id: x.object.try(:clid)).try(:id),
|
||||||
registered_at: x.object_registry.try(:crdate),
|
registered_at: x.object_registry.try(:crdate),
|
||||||
valid_from: x.object_registry.try(:crdate),
|
valid_from: x.object_registry.try(:crdate),
|
||||||
valid_to: x.exdate,
|
valid_to: x.exdate,
|
||||||
|
@ -29,14 +29,10 @@ module Legacy
|
||||||
legacy_id: x.id,
|
legacy_id: x.id,
|
||||||
legacy_registrar_id: x.object_registry.try(:crid),
|
legacy_registrar_id: x.object_registry.try(:crid),
|
||||||
legacy_registrant_id: x.registrant,
|
legacy_registrant_id: x.registrant,
|
||||||
statuses: x.states
|
statuses: Legacy::ObjectState.states_for_domain_at(x.id, time)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_current_changes(param)
|
|
||||||
p "not implemented #{__method__}"
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def changes_dates_for domain_id
|
def changes_dates_for domain_id
|
||||||
sql = %Q{SELECT dh.*, valid_from
|
sql = %Q{SELECT dh.*, valid_from
|
||||||
|
|
|
@ -80,12 +80,12 @@ module Legacy
|
||||||
map[state_id]
|
map[state_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_current_domain_object(param)
|
def get_current_domain_object(time, param)
|
||||||
p "not implemented #{__method__}"
|
d_his = Legacy::DomainHistory.get_record_at(object_id, historyid)
|
||||||
end
|
hash = d_his.get_current_domain_object(time, param)
|
||||||
|
hash[:statuses] = Legacy::ObjectState.states_for_domain_at(object_id, time + 1)
|
||||||
|
|
||||||
def get_current_changes(param)
|
hash
|
||||||
p "not implemented #{__method__}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -106,7 +106,7 @@ module Legacy
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_record_at domain_id, rec_id
|
def get_record_at domain_id, rec_id
|
||||||
sql = %Q{SELECT distinct t_2.id, state.*
|
sql = %Q{SELECT distinct t_2.historyid, state.*
|
||||||
FROM object_history t_2
|
FROM object_history t_2
|
||||||
JOIN object_state state ON (t_2.historyid >= state.ohid_from
|
JOIN object_state state ON (t_2.historyid >= state.ohid_from
|
||||||
AND (t_2.historyid <= state.ohid_to OR state.ohid_to IS NULL))
|
AND (t_2.historyid <= state.ohid_to OR state.ohid_to IS NULL))
|
||||||
|
@ -114,6 +114,21 @@ module Legacy
|
||||||
WHERE state.object_id=#{domain_id} AND state.id = #{rec_id};}
|
WHERE state.object_id=#{domain_id} AND state.id = #{rec_id};}
|
||||||
find_by_sql(sql).first
|
find_by_sql(sql).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def states_for_domain_at(domain_id, time)
|
||||||
|
sql = %Q{SELECT state.*
|
||||||
|
FROM object_history t_2
|
||||||
|
JOIN object_state state ON (t_2.historyid >= state.ohid_from
|
||||||
|
AND (t_2.historyid <= state.ohid_to OR state.ohid_to IS NULL))
|
||||||
|
AND t_2.id = state.object_id
|
||||||
|
WHERE state.object_id=#{domain_id}
|
||||||
|
AND (valid_from is null or valid_from <= '#{time.to_s}'::TIMESTAMPTZ)
|
||||||
|
AND (valid_to is null or valid_to >= '#{time}'::TIMESTAMPTZ)
|
||||||
|
}
|
||||||
|
arr = find_by_sql(sql).uniq
|
||||||
|
arr.map!(&:name) if arr.any?
|
||||||
|
arr.present? ? arr : [DomainStatus::OK]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -770,11 +770,13 @@ namespace :import do
|
||||||
# "reserved"=>false, "status_notes"=>{}, "statuses_backup"=>[]}
|
# "reserved"=>false, "status_notes"=>{}, "statuses_backup"=>[]}
|
||||||
|
|
||||||
Legacy::DomainHistory.uniq.where(id: 294516).pluck(:id).each do |legacy_domain_id|
|
Legacy::DomainHistory.uniq.where(id: 294516).pluck(:id).each do |legacy_domain_id|
|
||||||
|
next if Domain.find_by(legacy_id: legacy_domain_id).versions.where(event: :create).any?
|
||||||
# add here to skip domains whith create history
|
# add here to skip domains whith create history
|
||||||
|
|
||||||
# 1. add domain changes
|
# 1. add domain changes
|
||||||
# 2. add states
|
# 2. add states
|
||||||
# compose hash of change time -> Object changes
|
# compose hash of change time -> Object changes
|
||||||
|
last_changes = nil
|
||||||
history = Legacy::ObjectState.changes_dates_for(legacy_domain_id)
|
history = Legacy::ObjectState.changes_dates_for(legacy_domain_id)
|
||||||
p history.keys
|
p history.keys
|
||||||
p Legacy::DomainHistory.changes_dates_for(legacy_domain_id).keys
|
p Legacy::DomainHistory.changes_dates_for(legacy_domain_id).keys
|
||||||
|
@ -793,8 +795,7 @@ namespace :import do
|
||||||
event = :update
|
event = :update
|
||||||
event = :create if i == 0
|
event = :create if i == 0
|
||||||
responder = orig_history_klass[:klass].get_record_at(legacy_domain_id, orig_history_klass[:id])
|
responder = orig_history_klass[:klass].get_record_at(legacy_domain_id, orig_history_klass[:id])
|
||||||
responder.get_current_domain_object(orig_history_klass[:param])
|
p responder.get_current_domain_object(time, orig_history_klass[:param])
|
||||||
responder.get_current_changes(orig_history_klass[:param])
|
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue