Skip to content

Commit

Permalink
Merge pull request #1589 from dmitry-sinina/load_network_data_multipl…
Browse files Browse the repository at this point in the history
…e_transactions

Use multiple transactions to load custom network prefixes
  • Loading branch information
Ivanov-Anton authored Oct 22, 2024
2 parents a3d4549 + 96faeab commit a5b7652
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion db/custom_seeds/network_prefixes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
System::Network.insert_all!(networks) if networks.any?
System::Country.insert_all!(countries) if countries.any?
System::NetworkPrefix.insert_all!(network_prefixes) if network_prefixes.any?
end

Dir.glob('db/network_data/**/*.yml') do |f|
Dir.glob('db/network_data/**/*.yml') do |f|
System::NetworkPrefix.transaction do
puts "processing file #{f}:" # rubocop:disable Rails/Output
data = YAML.load_file(f, aliases: true)
n = data['networks']

System::Network.insert_all!(n) if n.any?
puts " loaded #{n.length} networks" # rubocop:disable Rails/Output
n_ids = n.map { |ni| ni['id'] }.uniq
Expand All @@ -35,7 +38,9 @@
no_prefixes = n_ids - np_ids
puts " networks without prefixes: #{no_prefixes}" if no_prefixes.any? # rubocop:disable Rails/Output
end
end

System::NetworkPrefix.transaction do
SqlCaller::Yeti.execute "SELECT pg_catalog.setval('sys.network_types_id_seq', MAX(id), true) FROM sys.network_types"
SqlCaller::Yeti.execute "SELECT pg_catalog.setval('sys.networks_id_seq', MAX(id), true) FROM sys.networks"
SqlCaller::Yeti.execute "SELECT pg_catalog.setval('sys.countries_id_seq', MAX(id), true) FROM sys.countries"
Expand Down

0 comments on commit a5b7652

Please sign in to comment.