Sha256: f5bef263dcb3d1f80bf56e311020c975cbca87738d3df8f8f8af6973b52afe8c
Contents?: true
Size: 814 Bytes
Versions: 24
Compression:
Stored size: 814 Bytes
Contents
connection = ApplicationRecord.connection state_inserts = [] state_values = -> do Spree::Country.where(states_required: true).each do |country| carmen_country = Carmen::Country.named(country.name) carmen_country.subregions.each do |subregion| name = connection.quote subregion.name abbr = connection.quote subregion.code country_id = connection.quote country.id state_inserts << [name, abbr, country_id].join(", ") end end state_inserts.map { |x| "(#{x})" } end columns = ["name", "abbr", "country_id"].map do |column| connection.quote_column_name column end.join(', ') state_values.call.each_slice(500) do |state_values_batch| connection.execute <<-SQL INSERT INTO spree_states (#{columns}) VALUES #{state_values_batch.join(", ")}; SQL end
Version data entries
24 entries across 24 versions & 1 rubygems