From 9849f76c1c134ae20100e9f09ca0947938167ec1 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 7 Mar 2018 10:28:34 +0100 Subject: [PATCH 1/3] Bring seeds.rb from ofn-install --- db/seeds.rb | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 82f95651bd..52a8a7c733 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,28 +1,29 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +require 'yaml' +require 'csv' # -- Spree -unless Spree::Country.find_by_name 'Australia' +unless Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE']) puts "[db:seed] Seeding Spree" Spree::Core::Engine.load_seed if defined?(Spree::Core) Spree::Auth::Engine.load_seed if defined?(Spree::Auth) end -# -- States -unless Spree::State.find_by_name 'Victoria' - country = Spree::Country.find_by_name('Australia') - puts "[db:seed] Seeding states" +country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE']) +puts "Country is #{country.to_s}" +puts "[db:seed] loading states yaml" +states = YAML::load_file "db/default/spree/states.yml" +puts "States: #{states.to_s}" - [ - ['ACT', 'ACT'], - ['New South Wales', 'NSW'], - ['Northern Territory', 'NT'], - ['Queensland', 'QLD'], - ['South Australia', 'SA'], - ['Tasmania', 'Tas'], - ['Victoria', 'Vic'], - ['Western Australia', 'WA'] - ].each do |state| - Spree::State.create!({"name"=>state[0], "abbr"=>state[1], :country=>country}, :without_protection => true) +# -- Seeding States +puts "[db:seed] Seeding states for " + country.name + +states.each do |state| + puts "State: " + state.to_s + unless Spree::State.find_by_name(state['name']) + Spree::State.create!({"name"=>state['name'], "abbr"=>state['abbr'], :country=>country}, without_protection: true) end + puts "set id" end From 5eb3dc4beb761493654a38b7a349ff097020291b Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 7 Mar 2018 10:30:12 +0100 Subject: [PATCH 2/3] Bring states.yml from l10n_au The states.yml present in this repo had a different format which doesn't work with the current seeds.rb that we brought from ofn-install. --- db/default/spree/states.yml | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/db/default/spree/states.yml b/db/default/spree/states.yml index 305e21ab39..134f0d8f2c 100644 --- a/db/default/spree/states.yml +++ b/db/default/spree/states.yml @@ -1,41 +1,33 @@ -#Australia -states_101: - name: Tasmania +--- +- name: Tasmania country_id: "12" id: "101" abbr: Tas -states_102: - name: Victoria +- name: Victoria country_id: "12" id: "102" abbr: Vic -states_103: - name: New South Wales +- name: New South Wales country_id: "12" id: "103" abbr: NSW -states_104: - name: ACT +- name: ACT country_id: "12" id: "104" abbr: ACT -states_105: - name: Queensland +- name: Queensland country_id: "12" id: "105" abbr: QLD -states_106: - name: South Australia +- name: South Australia country_id: "12" id: "106" abbr: SA -states_107: - name: Northern Territory +- name: Northern Territory country_id: "12" id: "107" abbr: NT -states_108: - name: Western Australia +- name: Western Australia country_id: "12" id: "108" - abbr: WA \ No newline at end of file + abbr: WA From c19c22cb17acfead08f8c3f18f4d176ea155041c Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 7 Mar 2018 10:51:54 +0100 Subject: [PATCH 3/3] Apply couple simple tweaks to seeds.rb --- db/seeds.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 52a8a7c733..9f9bc1efca 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,8 +1,6 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# require 'yaml' -require 'csv' # -- Spree unless Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE']) @@ -13,6 +11,7 @@ end country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE']) puts "Country is #{country.to_s}" + puts "[db:seed] loading states yaml" states = YAML::load_file "db/default/spree/states.yml" puts "States: #{states.to_s}" @@ -22,8 +21,11 @@ puts "[db:seed] Seeding states for " + country.name states.each do |state| puts "State: " + state.to_s + unless Spree::State.find_by_name(state['name']) - Spree::State.create!({"name"=>state['name'], "abbr"=>state['abbr'], :country=>country}, without_protection: true) + Spree::State.create!( + { name: state['name'], abbr: state['abbr'], country: country }, + without_protection: true + ) end - puts "set id" end