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

Version Path
spree_core-3.2.9 db/default/spree/states.rb
spree_core-3.3.6 db/default/spree/states.rb
spree_core-3.2.8 db/default/spree/states.rb
spree_core-3.3.5 db/default/spree/states.rb
spree_core-3.3.4 db/default/spree/states.rb
spree_core-3.2.7 db/default/spree/states.rb
spree_core-3.3.3 db/default/spree/states.rb
spree_core-3.2.6 db/default/spree/states.rb
spree_core-3.3.2 db/default/spree/states.rb
spree_core-3.2.5 db/default/spree/states.rb
spree_core-3.3.1 db/default/spree/states.rb
spree_core-3.2.4 db/default/spree/states.rb
spree_core-3.3.0 db/default/spree/states.rb
spree_core-3.3.0.rc4 db/default/spree/states.rb
spree_core-3.3.0.rc3 db/default/spree/states.rb
spree_core-3.2.3 db/default/spree/states.rb
spree_core-3.2.2 db/default/spree/states.rb
spree_core-3.3.0.rc2 db/default/spree/states.rb
spree_core-3.3.0.rc1 db/default/spree/states.rb
spree_core-3.2.1 db/default/spree/states.rb