Updates
This commit is contained in:
@@ -139,23 +139,37 @@ class GeoliteAsnImporter
|
||||
IPAddr.new(network) # This will raise if invalid
|
||||
|
||||
# Store raw GeoLite ASN data in network_data
|
||||
geolite_data = {
|
||||
geolite_asn_data = {
|
||||
asn: {
|
||||
autonomous_system_number: asn,
|
||||
autonomous_system_organization: asn_org
|
||||
}
|
||||
}
|
||||
|
||||
# Use upsert with JSONB merge
|
||||
# COALESCE handles the case where network_data might be NULL
|
||||
# || is PostgreSQL's JSONB concatenation/merge operator
|
||||
# jsonb_set merges the nested geolite data
|
||||
NetworkRange.upsert(
|
||||
{
|
||||
network: network,
|
||||
asn: asn,
|
||||
asn_org: asn_org,
|
||||
source: 'geolite_asn',
|
||||
network_data: { geolite: geolite_data },
|
||||
network_data: { geolite: geolite_asn_data },
|
||||
updated_at: Time.current
|
||||
},
|
||||
unique_by: :index_network_ranges_on_network_unique
|
||||
unique_by: :index_network_ranges_on_network_unique,
|
||||
on_duplicate: Arel.sql("
|
||||
asn = EXCLUDED.asn,
|
||||
asn_org = EXCLUDED.asn_org,
|
||||
network_data = COALESCE(network_ranges.network_data, '{}'::jsonb) ||
|
||||
jsonb_build_object('geolite',
|
||||
COALESCE(network_ranges.network_data->'geolite', '{}'::jsonb) ||
|
||||
EXCLUDED.network_data->'geolite'
|
||||
),
|
||||
updated_at = EXCLUDED.updated_at
|
||||
")
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user