solidus_core 3.0.0.rc2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/helpers/spree/products_helper.rb +1 -1
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +11 -11
- data/app/models/concerns/spree/active_storage_adapter.rb +2 -0
- data/app/models/concerns/spree/default_price.rb +63 -10
- data/app/models/spree/adjustment.rb +6 -5
- data/app/models/spree/base.rb +0 -17
- data/app/models/spree/calculator.rb +4 -0
- data/app/models/spree/customer_return.rb +3 -2
- data/app/models/spree/image/active_storage_attachment.rb +11 -8
- data/app/models/spree/image/paperclip_attachment.rb +3 -3
- data/app/models/spree/line_item.rb +2 -2
- data/app/models/spree/order.rb +12 -7
- data/app/models/spree/payment_method/bogus_credit_card.rb +13 -9
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +4 -4
- data/app/models/spree/payment_method.rb +3 -0
- data/app/models/spree/price.rb +1 -1
- data/app/models/spree/product/scopes.rb +5 -5
- data/app/models/spree/product.rb +12 -1
- data/app/models/spree/promotion/rules/item_total.rb +50 -6
- data/app/models/spree/promotion.rb +2 -2
- data/app/models/spree/promotion_action.rb +3 -0
- data/app/models/spree/promotion_code.rb +1 -1
- data/app/models/spree/promotion_rule.rb +4 -0
- data/app/models/spree/return_item.rb +2 -3
- data/app/models/spree/shipping_rate_tax.rb +1 -1
- data/app/models/spree/stock/availability.rb +11 -3
- data/app/models/spree/stock/simple_coordinator.rb +6 -11
- data/app/models/spree/stock_location.rb +1 -1
- data/app/models/spree/store_credit.rb +6 -1
- data/app/models/spree/tax_calculator/shipping_rate.rb +1 -1
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -2
- data/app/models/spree/taxon/paperclip_attachment.rb +3 -3
- data/app/models/spree/variant/price_selector.rb +16 -3
- data/app/models/spree/variant.rb +27 -17
- data/config/locales/en.yml +2 -0
- data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
- data/lib/generators/solidus/install/install_generator.rb +2 -2
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -1
- data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
- data/lib/generators/solidus/update/update_generator.rb +112 -0
- data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +78 -35
- data/lib/spree/app_configuration.rb +70 -0
- data/lib/spree/core/engine.rb +10 -11
- data/lib/spree/core/product_filters.rb +1 -1
- data/lib/spree/core/search/base.rb +1 -1
- data/lib/spree/core/state_machines/order.rb +1 -1
- data/lib/spree/core/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +5 -1
- data/lib/spree/core/versioned_value.rb +75 -0
- data/lib/spree/core.rb +17 -0
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/permitted_attributes.rb +8 -2
- data/lib/spree/preferences/configuration.rb +62 -0
- data/lib/spree/preferences/persistable.rb +23 -0
- data/lib/spree/preferences/preferable.rb +8 -0
- data/lib/spree/preferences/preferable_class_methods.rb +5 -3
- data/lib/spree/preferences/preference_differentiator.rb +28 -0
- data/lib/spree/testing_support/dummy_app/database.yml +42 -22
- data/lib/spree/testing_support/dummy_app.rb +33 -17
- data/lib/spree/testing_support/fixtures/file.txt +1 -0
- data/lib/spree/testing_support.rb +1 -1
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
- data/solidus_core.gemspec +20 -0
- metadata +29 -8
- data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
- data/lib/tasks/migrations/migrate_address_names.rake +0 -158
- data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -38
- data/lib/tasks/upgrade.rake +0 -13
@@ -27,7 +27,7 @@ module Spree::Preferences
|
|
27
27
|
end
|
28
28
|
|
29
29
|
default = options[:default]
|
30
|
-
default =
|
30
|
+
default = proc { options[:default] } unless default.is_a?(Proc)
|
31
31
|
|
32
32
|
# The defined preferences on a class are all those defined directly on
|
33
33
|
# that class as well as those defined on ancestors.
|
@@ -44,7 +44,7 @@ module Spree::Preferences
|
|
44
44
|
# is a pending preference before going to default
|
45
45
|
define_method preference_getter_method(name) do
|
46
46
|
value = preferences.fetch(name) do
|
47
|
-
default.call
|
47
|
+
default.call(*context_for_default)
|
48
48
|
end
|
49
49
|
value = preference_encryptor.decrypt(value) if preference_encryptor.present?
|
50
50
|
value
|
@@ -60,7 +60,9 @@ module Spree::Preferences
|
|
60
60
|
preferences_will_change! if respond_to?(:preferences_will_change!)
|
61
61
|
end
|
62
62
|
|
63
|
-
define_method preference_default_getter_method(name)
|
63
|
+
define_method preference_default_getter_method(name) do
|
64
|
+
default.call(*context_for_default)
|
65
|
+
end
|
64
66
|
|
65
67
|
define_method preference_type_getter_method(name) do
|
66
68
|
type
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Preferences
|
5
|
+
class PreferenceDifferentiator
|
6
|
+
attr_reader :config_class
|
7
|
+
|
8
|
+
def initialize(config_class)
|
9
|
+
@config_class = config_class
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(from:, to:)
|
13
|
+
preferences_from = config_class.new.load_defaults(from)
|
14
|
+
preferences_to = config_class.new.load_defaults(to)
|
15
|
+
preferences_from.reduce({}) do |changes, (pref_key, value_from)|
|
16
|
+
value_to = preferences_to[pref_key]
|
17
|
+
if value_from == value_to
|
18
|
+
changes
|
19
|
+
else
|
20
|
+
changes.merge(
|
21
|
+
pref_key => { from: value_from, to: value_to }
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,34 +1,54 @@
|
|
1
|
-
<%
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
<% db = case ENV['DB']
|
2
|
+
when 'mysql'
|
3
|
+
'mysql'
|
4
|
+
when 'postgres', 'postgresql'
|
5
|
+
'postgres'
|
6
|
+
when 'sqlite', '', nil
|
7
|
+
'sqlite'
|
8
|
+
else
|
9
|
+
raise "Invalid DB specified: #{ENV['DB']}"
|
10
|
+
end %>
|
11
|
+
<% db_host = case db
|
12
|
+
when 'mysql'
|
13
|
+
ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
|
14
|
+
when 'postgres'
|
15
|
+
ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
|
16
|
+
else
|
17
|
+
ENV['DB_HOST']
|
18
|
+
end %>
|
19
|
+
<% db_prefix = ENV['LIB_NAME'].presence || "solidus" %>
|
20
|
+
<% db_username = ENV['DB_USERNAME'] %>
|
21
|
+
<% db_password = ENV['DB_PASSWORD'] %>
|
22
|
+
<% case db
|
5
23
|
when 'mysql' %>
|
6
24
|
test:
|
7
25
|
adapter: mysql2
|
8
|
-
|
9
|
-
|
10
|
-
|
26
|
+
database: <%= db_prefix %>_test
|
27
|
+
<% unless db_username.blank? %>
|
28
|
+
username: <%= db_username %>
|
11
29
|
<% end %>
|
12
|
-
|
13
|
-
|
14
|
-
<%
|
15
|
-
|
30
|
+
<% unless db_password.blank? %>
|
31
|
+
password: <%= db_password %>
|
32
|
+
<% end %>
|
33
|
+
<% unless db_host.blank? %>
|
34
|
+
host: <%= db_host %>
|
16
35
|
<% end %>
|
17
|
-
|
18
|
-
<%
|
36
|
+
encoding: utf8
|
37
|
+
<% when 'postgres' %>
|
19
38
|
test:
|
20
39
|
adapter: postgresql
|
21
|
-
database: <%=
|
22
|
-
username: postgres
|
23
|
-
|
24
|
-
|
40
|
+
database: <%= db_prefix %>_test
|
41
|
+
username: <%= db_username.presence || "postgres" %>
|
42
|
+
<% unless db_password.blank? %>
|
43
|
+
password: <%= db_password %>
|
44
|
+
<% end %>
|
45
|
+
<% unless db_host.blank? %>
|
25
46
|
host: <%= db_host %>
|
26
|
-
<% end %>
|
27
|
-
|
47
|
+
<% end %>
|
48
|
+
min_messages: warning
|
49
|
+
<% when 'sqlite' %>
|
28
50
|
test:
|
29
51
|
adapter: sqlite3
|
30
|
-
database: db/<%=
|
52
|
+
database: db/<%= db_prefix %>_test.sqlite3
|
31
53
|
timeout: 10000
|
32
|
-
<% else %>
|
33
|
-
<% raise "Invalid DB specified: #{ENV['DB']}" %>
|
34
54
|
<% end %>
|
@@ -46,34 +46,53 @@ module DummyApp
|
|
46
46
|
end
|
47
47
|
|
48
48
|
class Application < ::Rails::Application
|
49
|
-
config.
|
49
|
+
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
|
50
|
+
# Make the test environment more production-like:
|
50
51
|
config.cache_classes = true
|
51
|
-
config.cache_store = :memory_store
|
52
|
-
config.serve_static_assets = true
|
53
|
-
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
|
54
|
-
config.whiny_nils = true
|
55
|
-
config.consider_all_requests_local = true
|
56
52
|
config.action_controller.allow_forgery_protection = false
|
57
53
|
config.action_controller.default_protect_from_forgery = false
|
54
|
+
config.action_mailer.perform_caching = false
|
55
|
+
config.i18n.fallbacks = true
|
56
|
+
|
57
|
+
# In the test environment, we use the `caching: true` RSpec metadata to
|
58
|
+
# enable caching on select specs. See
|
59
|
+
# core/lib/spree/testing_support/caching.rb. See also
|
60
|
+
# https://github.com/solidusio/solidus/issues/4110
|
58
61
|
config.action_controller.perform_caching = false
|
62
|
+
|
63
|
+
# Make debugging easier:
|
64
|
+
config.consider_all_requests_local = true
|
59
65
|
config.action_dispatch.show_exceptions = false
|
60
66
|
config.active_support.deprecation = :stderr
|
67
|
+
config.log_level = :debug
|
68
|
+
|
69
|
+
# Improve test suite performance:
|
70
|
+
config.eager_load = false
|
71
|
+
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
|
72
|
+
config.cache_store = :memory_store
|
73
|
+
|
74
|
+
# We don't use a web server, so we let Rails serve assets.
|
75
|
+
config.public_file_server.enabled = true
|
76
|
+
|
77
|
+
# We don't want to send email in the test environment.
|
61
78
|
config.action_mailer.delivery_method = :test
|
62
|
-
|
79
|
+
|
80
|
+
# No need to use credentials file in a test environment.
|
63
81
|
config.secret_key_base = 'SECRET_TOKEN'
|
64
82
|
|
65
|
-
|
83
|
+
# Set the preview path within the dummy app:
|
66
84
|
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
|
67
|
-
config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE
|
68
85
|
|
69
|
-
config.
|
86
|
+
config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE
|
87
|
+
config.active_record.dump_schema_after_migration = false
|
70
88
|
|
89
|
+
# Configure active storage to use storage within tmp folder
|
71
90
|
unless ENV['DISABLE_ACTIVE_STORAGE']
|
72
91
|
initializer 'solidus.active_storage' do
|
73
92
|
config.active_storage.service_configurations = {
|
74
93
|
test: {
|
75
94
|
service: 'Disk',
|
76
|
-
root:
|
95
|
+
root: Rails.root.join('tmp', 'storage')
|
77
96
|
}
|
78
97
|
}
|
79
98
|
config.active_storage.service = :test
|
@@ -94,12 +113,8 @@ module DummyApp
|
|
94
113
|
config.paths['db/migrate'] = migration_dirs
|
95
114
|
ActiveRecord::Migrator.migrations_paths = migration_dirs
|
96
115
|
|
97
|
-
config.
|
98
|
-
|
99
|
-
if config.respond_to?(:assets)
|
100
|
-
config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__)
|
101
|
-
config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__)
|
102
|
-
end
|
116
|
+
config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__)
|
117
|
+
config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__)
|
103
118
|
|
104
119
|
config.paths["config/database"] = File.expand_path('dummy_app/database.yml', __dir__)
|
105
120
|
config.paths['app/views'] = File.expand_path('dummy_app/views', __dir__)
|
@@ -116,6 +131,7 @@ ActiveSupport.on_load(:action_controller) do
|
|
116
131
|
end
|
117
132
|
|
118
133
|
Spree.user_class = 'Spree::LegacyUser'
|
134
|
+
Spree.load_defaults(Spree.solidus_version)
|
119
135
|
Spree.config do |config|
|
120
136
|
config.mails_from = "store@example.com"
|
121
137
|
|
@@ -0,0 +1 @@
|
|
1
|
+
This is a text file
|
@@ -25,7 +25,7 @@ module Spree
|
|
25
25
|
factory_bot_paths: "Spree::TestingSupport::FactoryBot.definition_file_paths",
|
26
26
|
check_factory_bot_version: "Spree::TestingSupport::FactoryBot.check_version",
|
27
27
|
load_all_factories: "Spree::TestingSupport::FactoryBot.add_paths_and_load!",
|
28
|
-
deprecator: Spree::
|
28
|
+
deprecator: Spree::Deprecation
|
29
29
|
)
|
30
30
|
end
|
31
31
|
end
|
data/solidus_core.gemspec
CHANGED
@@ -42,4 +42,24 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.add_dependency 'kt-paperclip', '~> 6.3'
|
43
43
|
s.add_dependency 'ransack', '~> 2.0'
|
44
44
|
s.add_dependency 'state_machines-activerecord', '~> 0.6'
|
45
|
+
|
46
|
+
s.post_install_message = <<-MSG
|
47
|
+
-------------------------------------------------------------
|
48
|
+
Thank you for using Solidus
|
49
|
+
-------------------------------------------------------------
|
50
|
+
If this is a fresh install, don't forget to run the Solidus
|
51
|
+
installer with the following command:
|
52
|
+
|
53
|
+
$ bin/rails g solidus:install
|
54
|
+
|
55
|
+
If you are updating Solidus from an older version, please run
|
56
|
+
the following commands to complete the update:
|
57
|
+
|
58
|
+
$ bin/rails solidus:upgrade
|
59
|
+
|
60
|
+
Please report any issues at:
|
61
|
+
- https://github.com/solidusio/solidus/issues
|
62
|
+
- http://slack.solidus.io/
|
63
|
+
-------------------------------------------------------------
|
64
|
+
MSG
|
45
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -609,7 +609,6 @@ files:
|
|
609
609
|
- app/models/spree/tax/item_tax.rb
|
610
610
|
- app/models/spree/tax/order_adjuster.rb
|
611
611
|
- app/models/spree/tax/order_tax.rb
|
612
|
-
- app/models/spree/tax/shipping_rate_taxer.rb
|
613
612
|
- app/models/spree/tax/tax_helpers.rb
|
614
613
|
- app/models/spree/tax/tax_location.rb
|
615
614
|
- app/models/spree/tax_calculator/default.rb
|
@@ -705,6 +704,7 @@ files:
|
|
705
704
|
- db/migrate/20200530111458_add_bcc_email_to_spree_stores.rb
|
706
705
|
- db/migrate/20201008213609_add_discontinue_on_to_spree_products.rb
|
707
706
|
- db/migrate/20210122110141_add_name_to_spree_addresses.rb
|
707
|
+
- db/migrate/20210312061050_change_column_null_on_prices.rb
|
708
708
|
- db/seeds.rb
|
709
709
|
- lib/generators/solidus/install/install_generator.rb
|
710
710
|
- lib/generators/solidus/install/templates/config/initializers/spree.rb.tt
|
@@ -712,6 +712,8 @@ files:
|
|
712
712
|
- lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js
|
713
713
|
- lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/backend/all.css
|
714
714
|
- lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css
|
715
|
+
- lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt
|
716
|
+
- lib/generators/solidus/update/update_generator.rb
|
715
717
|
- lib/generators/spree/custom_user/custom_user_generator.rb
|
716
718
|
- lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt
|
717
719
|
- lib/generators/spree/custom_user/templates/migration.rb.tt
|
@@ -765,6 +767,7 @@ files:
|
|
765
767
|
- lib/spree/core/stock_configuration.rb
|
766
768
|
- lib/spree/core/validators/email.rb
|
767
769
|
- lib/spree/core/version.rb
|
770
|
+
- lib/spree/core/versioned_value.rb
|
768
771
|
- lib/spree/deprecation.rb
|
769
772
|
- lib/spree/encryptor.rb
|
770
773
|
- lib/spree/event.rb
|
@@ -801,8 +804,10 @@ files:
|
|
801
804
|
- lib/spree/permission_sets/user_management.rb
|
802
805
|
- lib/spree/permitted_attributes.rb
|
803
806
|
- lib/spree/preferences/configuration.rb
|
807
|
+
- lib/spree/preferences/persistable.rb
|
804
808
|
- lib/spree/preferences/preferable.rb
|
805
809
|
- lib/spree/preferences/preferable_class_methods.rb
|
810
|
+
- lib/spree/preferences/preference_differentiator.rb
|
806
811
|
- lib/spree/preferences/scoped_store.rb
|
807
812
|
- lib/spree/preferences/static_model_preferences.rb
|
808
813
|
- lib/spree/preferences/statically_configurable.rb
|
@@ -888,6 +893,7 @@ files:
|
|
888
893
|
- lib/spree/testing_support/factories/zone_factory.rb
|
889
894
|
- lib/spree/testing_support/factory_bot.rb
|
890
895
|
- lib/spree/testing_support/fixtures/blank.jpg
|
896
|
+
- lib/spree/testing_support/fixtures/file.txt
|
891
897
|
- lib/spree/testing_support/flash.rb
|
892
898
|
- lib/spree/testing_support/job_helpers.rb
|
893
899
|
- lib/spree/testing_support/order_walkthrough.rb
|
@@ -901,9 +907,7 @@ files:
|
|
901
907
|
- lib/spree/testing_support/url_helpers.rb
|
902
908
|
- lib/spree/user_class_handle.rb
|
903
909
|
- lib/spree_core.rb
|
904
|
-
- lib/tasks/
|
905
|
-
- lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake
|
906
|
-
- lib/tasks/upgrade.rake
|
910
|
+
- lib/tasks/solidus/delete_prices_with_nil_amount.rake
|
907
911
|
- solidus_core.gemspec
|
908
912
|
- vendor/assets/javascripts/jquery.payment.js
|
909
913
|
- vendor/assets/javascripts/jsuri.js
|
@@ -912,7 +916,24 @@ homepage: http://solidus.io
|
|
912
916
|
licenses:
|
913
917
|
- BSD-3-Clause
|
914
918
|
metadata: {}
|
915
|
-
post_install_message:
|
919
|
+
post_install_message: |
|
920
|
+
-------------------------------------------------------------
|
921
|
+
Thank you for using Solidus
|
922
|
+
-------------------------------------------------------------
|
923
|
+
If this is a fresh install, don't forget to run the Solidus
|
924
|
+
installer with the following command:
|
925
|
+
|
926
|
+
$ bin/rails g solidus:install
|
927
|
+
|
928
|
+
If you are updating Solidus from an older version, please run
|
929
|
+
the following commands to complete the update:
|
930
|
+
|
931
|
+
$ bin/rails solidus:upgrade
|
932
|
+
|
933
|
+
Please report any issues at:
|
934
|
+
- https://github.com/solidusio/solidus/issues
|
935
|
+
- http://slack.solidus.io/
|
936
|
+
-------------------------------------------------------------
|
916
937
|
rdoc_options: []
|
917
938
|
require_paths:
|
918
939
|
- lib
|
@@ -927,7 +948,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
927
948
|
- !ruby/object:Gem::Version
|
928
949
|
version: 1.8.23
|
929
950
|
requirements: []
|
930
|
-
rubygems_version: 3.
|
951
|
+
rubygems_version: 3.2.20
|
931
952
|
signing_key:
|
932
953
|
specification_version: 4
|
933
954
|
summary: Essential models, mailers, and classes for the Solidus e-commerce project.
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
module Tax
|
5
|
-
# Used to build shipping rate taxes
|
6
|
-
class ShippingRateTaxer
|
7
|
-
# Build shipping rate taxes for a shipping rate
|
8
|
-
# Modifies the passed-in shipping rate with associated shipping rate taxes.
|
9
|
-
# @param [Spree::ShippingRate] shipping_rate The shipping rate to add taxes to.
|
10
|
-
# This parameter will be modified.
|
11
|
-
# @return [Spree::ShippingRate] The shipping rate with associated tax objects
|
12
|
-
def tax(shipping_rate)
|
13
|
-
taxes = Spree::Config.shipping_rate_tax_calculator_class.new(shipping_rate.order).calculate(shipping_rate)
|
14
|
-
taxes.each do |tax|
|
15
|
-
shipping_rate.taxes.build(
|
16
|
-
amount: tax.amount,
|
17
|
-
tax_rate: tax.tax_rate
|
18
|
-
)
|
19
|
-
end
|
20
|
-
shipping_rate
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'thor'
|
4
|
-
|
5
|
-
namespace :solidus do
|
6
|
-
namespace :migrations do
|
7
|
-
namespace :migrate_address_names do
|
8
|
-
desc 'Backfills Spree::Address name attribute using firstname and lastname
|
9
|
-
concatenation in order to retain historical data when upgrading to new
|
10
|
-
address name format'
|
11
|
-
task up: :environment do
|
12
|
-
puts "Combining addresses' firstname and lastname into name ... "
|
13
|
-
class Spree::AddressForMigration < ApplicationRecord
|
14
|
-
self.table_name = 'spree_addresses'
|
15
|
-
end
|
16
|
-
|
17
|
-
records = Spree::AddressForMigration.unscoped.where(name: [nil, ''])
|
18
|
-
count = records.count
|
19
|
-
connection = ActiveRecord::Base.connection
|
20
|
-
adapter_name = connection.adapter_name.downcase
|
21
|
-
shell = Thor::Shell::Basic.new
|
22
|
-
puts " Your DB contains #{count} addresses that may be affected by this task."
|
23
|
-
# `trim` is not needed for pg or mysql when using `concat_ws`:
|
24
|
-
# select concat_ws('joinstring', 'foo', null);
|
25
|
-
# concat_ws
|
26
|
-
# -----------
|
27
|
-
# foo
|
28
|
-
# (1 row)
|
29
|
-
# select concat_ws('joinstring', 'foo', null) = trim(concat_ws('joinstring', 'foo', null));
|
30
|
-
# ?column?
|
31
|
-
# ----------
|
32
|
-
# t
|
33
|
-
# (1 row)
|
34
|
-
unless count.zero?
|
35
|
-
concat_statement = begin
|
36
|
-
case adapter_name
|
37
|
-
when /sqlite/
|
38
|
-
"name = TRIM(COALESCE(firstname, '') || ' ' || COALESCE(lastname, ''))"
|
39
|
-
when /postgres/, /mysql2/
|
40
|
-
"name = CONCAT_WS(' ', firstname, lastname)"
|
41
|
-
else
|
42
|
-
abort " No migration path available for adapter #{adapter_name}. Please write your own."
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# The batch size should be limited to avoid locking the table records for too long. These are
|
47
|
-
# the numbers I got with 1_000_000 records in `spree_addresses`, all with different name and
|
48
|
-
# surname, with postgresql:
|
49
|
-
#
|
50
|
-
# Updating 1000000 records in one shot
|
51
|
-
# batch took 178 seconds
|
52
|
-
#
|
53
|
-
# Updating 1000000 addresses in batches of 200000
|
54
|
-
# batch took 36 seconds
|
55
|
-
# batch took 31 seconds
|
56
|
-
# batch took 31 seconds
|
57
|
-
# batch took 31 seconds
|
58
|
-
# batch took 30 seconds
|
59
|
-
#
|
60
|
-
# Updating 1000000 addresses in batches of 150000
|
61
|
-
# batch took 29 seconds
|
62
|
-
# batch took 27 seconds
|
63
|
-
# batch took 27 seconds
|
64
|
-
# batch took 27 seconds
|
65
|
-
# batch took 26 seconds
|
66
|
-
# batch took 26 seconds
|
67
|
-
# batch took 19 seconds
|
68
|
-
#
|
69
|
-
# Updating 1000000 addresses in batches of 100000
|
70
|
-
# batch took 17 seconds
|
71
|
-
# batch took 15 seconds
|
72
|
-
# batch took 17 seconds
|
73
|
-
# batch took 17 seconds
|
74
|
-
# batch took 17 seconds
|
75
|
-
# batch took 17 seconds
|
76
|
-
# batch took 17 seconds
|
77
|
-
# batch took 17 seconds
|
78
|
-
# batch took 17 seconds
|
79
|
-
# batch took 17 seconds
|
80
|
-
#
|
81
|
-
# This is with mysql:
|
82
|
-
# Updating 1000000 records in one shot
|
83
|
-
# batch updated in 153 seconds
|
84
|
-
#
|
85
|
-
# Updating 1000000 records in batches of 200000, this may take a while...
|
86
|
-
# batch took 41 seconds
|
87
|
-
# batch took 37 seconds
|
88
|
-
# batch took 35 seconds
|
89
|
-
# batch took 28 seconds
|
90
|
-
# batch took 27 seconds
|
91
|
-
#
|
92
|
-
# Updating 1000000 records in batches of 150000, this may take a while...
|
93
|
-
# batch took 30 seconds
|
94
|
-
# batch took 29 seconds
|
95
|
-
# batch took 18 seconds
|
96
|
-
# batch took 18 seconds
|
97
|
-
# batch took 17 seconds
|
98
|
-
# batch took 29 seconds
|
99
|
-
# batch took 12 seconds
|
100
|
-
#
|
101
|
-
# Updating 1000000 records in batches of 100000, this may take a while...
|
102
|
-
# batch took 10 seconds
|
103
|
-
# batch took 11 seconds
|
104
|
-
# batch took 12 seconds
|
105
|
-
# batch took 13 seconds
|
106
|
-
# batch took 12 seconds
|
107
|
-
# batch took 12 seconds
|
108
|
-
# batch took 14 seconds
|
109
|
-
# batch took 19 seconds
|
110
|
-
# batch took 20 seconds
|
111
|
-
# batch took 21 seconds
|
112
|
-
#
|
113
|
-
# Please note that the migration will be much faster when there's no index
|
114
|
-
# on the `name` column. For example, with mysql each batch takes exactly
|
115
|
-
# the same time:
|
116
|
-
#
|
117
|
-
# Updating 1000000 records in batches of 200000, this may take a while...
|
118
|
-
# batch took 17 seconds
|
119
|
-
# batch took 17 seconds
|
120
|
-
# batch took 17 seconds
|
121
|
-
# batch took 16 seconds
|
122
|
-
# batch took 17 seconds
|
123
|
-
#
|
124
|
-
# So, if special need arise, one can drop the index added with migration
|
125
|
-
# 20210122110141_add_name_to_spree_addresses.rb and add the index later,
|
126
|
-
# in non blocking ways. For postgresql:
|
127
|
-
# add_index(:spree_addresses, :name, algorithm: :concurrently)
|
128
|
-
#
|
129
|
-
# For mysql 5.6:
|
130
|
-
# sql = "ALTER TABLE spree_addresses ADD INDEX index_spree_addresses_on_name (name), ALGORITHM=INPLACE, LOCK=NONE;"
|
131
|
-
# ActiveRecord::Base.connection.execute sql
|
132
|
-
#
|
133
|
-
puts ' Data migration will happen in batches. The default value is 100_000, which should take less than 20 seconds on mysql or postgresql.'
|
134
|
-
size = shell.ask(' Please enter a different batch size, or press return to confirm the default: ')
|
135
|
-
size = (size.presence || 100_000).to_i
|
136
|
-
|
137
|
-
abort " Invalid batch size number #{size}, please run the task again." unless size.positive?
|
138
|
-
|
139
|
-
batches_total = (count / size).ceil
|
140
|
-
puts " We're going to migrate #{count} records in #{batches_total} batches of #{size}."
|
141
|
-
|
142
|
-
answer = shell.ask(' Do you want to proceed?', limited_to: ['Y', 'N'], case_insensitive: true)
|
143
|
-
if answer == 'Y'
|
144
|
-
puts " Updating #{count} records in batches of #{size}, this may take a while..."
|
145
|
-
|
146
|
-
records.in_batches(of: size).each.with_index(1) do |batch, index|
|
147
|
-
now = Time.zone.now
|
148
|
-
batch.update_all(concat_statement)
|
149
|
-
puts " Batch #{index}/#{batches_total} done in #{(Time.zone.now - now).to_i} seconds."
|
150
|
-
end
|
151
|
-
else
|
152
|
-
puts " Database not migrated. Please, make sure to fill address's name field on your own."
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|