Sha256: 354af5697cb7f3d5e89681efdc8cb7114eb36c1ac492ff715174dd4164e3c974

Contents?: true

Size: 815 Bytes

Versions: 34

Compression:

Stored size: 815 Bytes

Contents

connection = ActiveRecord::Base.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

34 entries across 34 versions & 1 rubygems

Version Path
spree_core-3.1.0.rc1 db/default/spree/states.rb
spree_core-3.0.8 db/default/spree/states.rb
spree_core-3.0.7 db/default/spree/states.rb
spree_core-3.0.6.1 db/default/spree/states.rb
spree_core-3.0.6 db/default/spree/states.rb
spree_core-3.0.5 db/default/spree/states.rb
spree_core-3.0.4 db/default/spree/states.rb
spree_core-3.0.3 db/default/spree/states.rb
spree_core-3.0.2 db/default/spree/states.rb
spree_core-3.0.1 db/default/spree/states.rb
spree_core-3.0.0 db/default/spree/states.rb
spree_core-3.0.0.rc4 db/default/spree/states.rb
spree_core-3.0.0.rc3 db/default/spree/states.rb
spree_core-3.0.0.rc1 db/default/spree/states.rb