solidus_core 3.0.0.rc2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35ced6fd29e1822a14a86b637243c871d373b2ead2d575e7737d0fa35907a48d
4
- data.tar.gz: ab72677886bf4ce7c2ba48dbe711fe73aa5e1193d990fb4d7cd872035e247f33
3
+ metadata.gz: 81eb655ea1d37e3bcff2919b25a0eeb4bfe3ab9e1a63bde79634d2dc4aabdbf6
4
+ data.tar.gz: 6da9f5ee0d1c4f6ac1207360a0b02aab57815979c9cfcc92fc0ac7d96045c4e8
5
5
  SHA512:
6
- metadata.gz: 1b18d6067bfbe97ce226fd82fb9a48da5e16eadeef3ac3b758c7d159dc079aef8880396a2acb9c0e23f98953d331f8161ba3271f780c21de04c1f9e501b1136b
7
- data.tar.gz: 5cc4ad46294a842daa2850e785d08dbfa4f01b28f5806449457fb498898c557866590ed7d332888d6c5fae72ae1ee81fbf3d4fa1ead5aa682af226debce6a890
6
+ metadata.gz: accdc98f491008a0541f3b03e4354724d772ea47546419871cb39a0b4431d9fba8db6757ae7b41dd0c0d3347948d31b13cb72ccac2fee9e8bf96a3de5d00a629
7
+ data.tar.gz: 7b4d5570a1e2b882d9d6186840e0f324fdf44af55347a14434c3ce58d8cabba0331daca21a65c34e49c70d26c631d24794610e45cde69565087ca7c40caf582f
@@ -107,6 +107,8 @@ module Spree
107
107
 
108
108
  def url(style = default_style)
109
109
  attachment.url(style)
110
+ rescue ActiveStorage::FileNotFoundError
111
+ "noimage/#{style}.png"
110
112
  end
111
113
 
112
114
  def destroy_attachment(_name)
@@ -9,11 +9,9 @@ module Spree
9
9
  class Attachment
10
10
  delegate_missing_to :@attachment
11
11
 
12
- DEFAULT_SIZE = '100%'
13
-
14
12
  def initialize(attachment, styles: {})
15
13
  @attachment = attachment
16
- @styles = styles
14
+ @styles = normalize_styles(styles)
17
15
  end
18
16
 
19
17
  def exists?
@@ -21,20 +19,18 @@ module Spree
21
19
  end
22
20
 
23
21
  def filename
24
- blob.filename.to_s
22
+ blob&.filename.to_s
25
23
  end
26
24
 
27
25
  def url(style = nil)
28
- variant(style).url
26
+ variant(style)&.url
29
27
  end
30
28
 
31
29
  def variant(style = nil)
32
- size = style_to_size(style&.to_sym)
30
+ size = style_to_size(style)
33
31
  @attachment.variant(
34
- resize: size,
35
- strip: true,
36
- 'auto-orient': true,
37
- colorspace: 'sRGB',
32
+ resize_to_limit: size,
33
+ strip: true
38
34
  ).processed
39
35
  end
40
36
 
@@ -61,8 +57,12 @@ module Spree
61
57
  @attachment.metadata
62
58
  end
63
59
 
60
+ def normalize_styles(styles)
61
+ styles.transform_values { |v| v.split('x') }
62
+ end
63
+
64
64
  def style_to_size(style)
65
- @styles.fetch(style) { DEFAULT_SIZE }
65
+ @styles.fetch(style&.to_sym) { [width, height] }
66
66
  end
67
67
  end
68
68
  end
@@ -1,26 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Spree::Base < ActiveRecord::Base
4
- include Spree::Preferences::Preferable
5
4
  include Spree::Core::Permalinks
6
5
  include Spree::RansackableAttributes
7
6
 
8
- def initialize_preference_defaults
9
- if has_attribute?(:preferences)
10
- self.preferences = default_preferences.merge(preferences)
11
- end
12
- end
13
-
14
- # Only run preference initialization on models which requires it. Improves
15
- # performance of record initialization slightly.
16
- def self.preference(*args)
17
- # after_initialize can be called multiple times with the same symbol, it
18
- # will only be called once on initialization.
19
- serialize :preferences, Hash
20
- after_initialize :initialize_preference_defaults
21
- super
22
- end
23
-
24
7
  self.abstract_class = true
25
8
 
26
9
  # Provides a scope that should be included any time products
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
4
+
3
5
  module Spree
4
6
  class Calculator < Spree::Base
7
+ include Spree::Preferences::Persistable
8
+
5
9
  belongs_to :calculable, polymorphic: true, optional: true
6
10
 
7
11
  # This method calls a compute_<computable> method. must be overriden in concrete calculator.
@@ -7,6 +7,10 @@ module Spree::Image::ActiveStorageAttachment
7
7
  delegate :width, :height, to: :attachment, prefix: true
8
8
 
9
9
  included do
10
+ validates :attachment, presence: true
11
+ validate :attachment_is_an_image
12
+ validate :supported_content_type
13
+
10
14
  has_attachment :attachment,
11
15
  styles: {
12
16
  mini: '48x48>',
@@ -15,7 +19,11 @@ module Spree::Image::ActiveStorageAttachment
15
19
  large: '1200x1200>'
16
20
  },
17
21
  default_style: :product
18
- validates :attachment, presence: true
19
- validate :attachment_is_an_image
22
+
23
+ def supported_content_type
24
+ unless attachment.content_type.in?(Spree::Config.allowed_image_mime_types)
25
+ errors.add(:attachment, :content_type_not_supported)
26
+ end
27
+ end
20
28
  end
21
29
  end
@@ -15,7 +15,7 @@ module Spree::Image::PaperclipAttachment
15
15
  convert_options: { all: '-strip -auto-orient -colorspace sRGB' }
16
16
  validates_attachment :attachment,
17
17
  presence: true,
18
- content_type: { content_type: %w[image/jpeg image/jpg image/png image/gif] }
18
+ content_type: { content_type: Spree::Config.allowed_image_mime_types }
19
19
 
20
20
  # save the w,h of the original image (from which others can be calculated)
21
21
  # we need to look at the write-queue for images which have not been saved yet
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
3
4
  require 'spree/preferences/statically_configurable'
4
5
 
5
6
  module Spree
@@ -11,6 +12,8 @@ module Spree
11
12
  # This class is not meant to be instantiated. Please create instances of concrete payment methods.
12
13
  #
13
14
  class PaymentMethod < Spree::Base
15
+ include Spree::Preferences::Persistable
16
+
14
17
  preference :server, :string, default: 'test'
15
18
  preference :test_mode, :boolean, default: true
16
19
 
@@ -9,6 +9,10 @@ module Spree
9
9
 
10
10
  VALID_CCS = ['1', TEST_VISA, TEST_MC, TEST_AMEX, TEST_DISC].flatten
11
11
 
12
+ AUTHORIZATION_CODE = '12345'
13
+ FAILURE_MESSAGE = 'Bogus Gateway: Forced failure'
14
+ SUCCESS_MESSAGE = 'Bogus Gateway: Forced success'
15
+
12
16
  attr_accessor :test
13
17
 
14
18
  def gateway_class
@@ -26,40 +30,40 @@ module Spree
26
30
  def authorize(_money, credit_card, _options = {})
27
31
  profile_id = credit_card.gateway_customer_profile_id
28
32
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
29
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'D' })
33
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'D' })
30
34
  else
31
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { message: 'Bogus Gateway: Forced failure' }, test: true)
35
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, { message: FAILURE_MESSAGE }, test: true)
32
36
  end
33
37
  end
34
38
 
35
39
  def purchase(_money, credit_card, _options = {})
36
40
  profile_id = credit_card.gateway_customer_profile_id
37
41
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
38
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'M' })
42
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'M' })
39
43
  else
40
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', message: 'Bogus Gateway: Forced failure', test: true)
44
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, message: FAILURE_MESSAGE, test: true)
41
45
  end
42
46
  end
43
47
 
44
48
  def credit(_money, _credit_card, _response_code, _options = {})
45
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
49
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
46
50
  end
47
51
 
48
52
  def capture(_money, authorization, _gateway_options)
49
53
  if authorization == '12345'
50
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true)
54
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true)
51
55
  else
52
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', error: 'Bogus Gateway: Forced failure', test: true)
56
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, error: FAILURE_MESSAGE, test: true)
53
57
  end
54
58
  end
55
59
 
56
60
  def void(_response_code, _credit_card, _options = {})
57
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
61
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
58
62
  end
59
63
 
60
64
  # @see Spree::PaymentMethod#try_void
61
65
  def try_void(_payment)
62
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
66
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
63
67
  end
64
68
 
65
69
  def test?
@@ -9,17 +9,17 @@ module Spree
9
9
 
10
10
  def authorize(_money, credit_card, _options = {})
11
11
  if VALID_CCS.include? credit_card.number
12
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'A' })
12
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' })
13
13
  else
14
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { message: 'Bogus Gateway: Forced failure' }, test: true)
14
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, { message: FAILURE_MESSAGE }, test: true)
15
15
  end
16
16
  end
17
17
 
18
18
  def purchase(_money, credit_card, _options = {})
19
19
  if VALID_CCS.include? credit_card.number
20
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'A' })
20
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' })
21
21
  else
22
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', message: 'Bogus Gateway: Forced failure', test: true)
22
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, message: FAILURE_MESSAGE, test: true)
23
23
  end
24
24
  end
25
25
  end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
4
+
3
5
  module Spree
4
6
  # Base class for all types of promotion action.
5
7
  #
6
8
  # PromotionActions perform the necessary tasks when a promotion is activated
7
9
  # by an event and determined to be eligible.
8
10
  class PromotionAction < Spree::Base
11
+ include Spree::Preferences::Persistable
9
12
  include Spree::SoftDeletable
10
13
 
11
14
  belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_actions, optional: true
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
4
+
3
5
  module Spree
4
6
  # Base class for all promotion rules
5
7
  class PromotionRule < Spree::Base
8
+ include Spree::Preferences::Persistable
9
+
6
10
  belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_rules, optional: true
7
11
 
8
12
  scope :of_type, ->(type) { where(type: type) }
@@ -182,7 +182,7 @@ module Solidus
182
182
  end
183
183
 
184
184
  bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
185
- run "spring stop"
185
+ run "spring stop" if defined?(Spring)
186
186
 
187
187
  @plugin_generators_to_run.each do |plugin_generator_name|
188
188
  generate "#{plugin_generator_name} --skip_migrations=true"
@@ -445,6 +445,14 @@ module Spree
445
445
  # Enumerable of images adhering to the present_image_class interface
446
446
  class_name_attribute :image_attachment_module, default: 'Spree::Image::ActiveStorageAttachment'
447
447
 
448
+ # @!attribute [rw] allowed_image_mime_types
449
+ #
450
+ # Defines which MIME types are allowed for images
451
+ # `%w(image/jpeg image/jpg image/png image/gif).freeze` is the default.
452
+ #
453
+ # @return [Array]
454
+ class_name_attribute :allowed_image_mime_types, default: %w(image/jpeg image/jpg image/png image/gif).freeze
455
+
448
456
  # Allows switching attachment library for Taxon
449
457
  #
450
458
  # `Spree::Taxon::ActiveStorageAttachment`
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "3.0.0.rc2"
4
+ VERSION = "3.0.0"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
@@ -3,7 +3,7 @@
3
3
  require 'active_support/deprecation'
4
4
 
5
5
  module Spree
6
- Deprecation = ActiveSupport::Deprecation.new('3.0', 'Solidus')
6
+ Deprecation = ActiveSupport::Deprecation.new('4.0', 'Solidus')
7
7
 
8
8
  # This DeprecatedInstanceVariableProxy transforms instance variable to
9
9
  # deprecated instance variable.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Preferences
5
+ module Persistable
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include Spree::Preferences::Preferable
10
+ serialize :preferences, Hash
11
+ after_initialize :initialize_preference_defaults
12
+ end
13
+
14
+ private
15
+
16
+ def initialize_preference_defaults
17
+ if has_attribute?(:preferences)
18
+ self.preferences = default_preferences.merge(preferences)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -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::Deprecator
28
+ deprecator: Spree::Deprecation
29
29
  )
30
30
  end
31
31
  end
@@ -0,0 +1 @@
1
+ This is a text file
@@ -2,12 +2,14 @@
2
2
 
3
3
  namespace :solidus do
4
4
  namespace :upgrade do
5
- desc "Upgrade Solidus to version 2.11"
6
- task two_point_eleven: [
7
- 'solidus:migrations:migrate_default_billing_addresses_to_address_book:up',
8
- 'solidus:migrations:migrate_address_names:up'
5
+ task three_point_zero: [
6
+ 'railties:install:migrations',
7
+ 'db:migrate'
9
8
  ] do
10
- puts "Your Solidus install is ready for Solidus 2.11"
9
+ puts "Your Solidus install is ready for Solidus 3.0"
11
10
  end
12
11
  end
12
+
13
+ desc "Upgrade to the current Solidus version"
14
+ task upgrade: 'upgrade:three_point_zero'
13
15
  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.0.0.rc2
4
+ version: 3.0.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-03-10 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -801,6 +801,7 @@ files:
801
801
  - lib/spree/permission_sets/user_management.rb
802
802
  - lib/spree/permitted_attributes.rb
803
803
  - lib/spree/preferences/configuration.rb
804
+ - lib/spree/preferences/persistable.rb
804
805
  - lib/spree/preferences/preferable.rb
805
806
  - lib/spree/preferences/preferable_class_methods.rb
806
807
  - lib/spree/preferences/scoped_store.rb
@@ -888,6 +889,7 @@ files:
888
889
  - lib/spree/testing_support/factories/zone_factory.rb
889
890
  - lib/spree/testing_support/factory_bot.rb
890
891
  - lib/spree/testing_support/fixtures/blank.jpg
892
+ - lib/spree/testing_support/fixtures/file.txt
891
893
  - lib/spree/testing_support/flash.rb
892
894
  - lib/spree/testing_support/job_helpers.rb
893
895
  - lib/spree/testing_support/order_walkthrough.rb
@@ -901,8 +903,6 @@ files:
901
903
  - lib/spree/testing_support/url_helpers.rb
902
904
  - lib/spree/user_class_handle.rb
903
905
  - lib/spree_core.rb
904
- - lib/tasks/migrations/migrate_address_names.rake
905
- - lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake
906
906
  - lib/tasks/upgrade.rake
907
907
  - solidus_core.gemspec
908
908
  - vendor/assets/javascripts/jquery.payment.js
@@ -912,7 +912,24 @@ homepage: http://solidus.io
912
912
  licenses:
913
913
  - BSD-3-Clause
914
914
  metadata: {}
915
- post_install_message:
915
+ post_install_message: |
916
+ -------------------------------------------------------------
917
+ Thank you for using Solidus
918
+ -------------------------------------------------------------
919
+ If this is a fresh install, don't forget to run the Solidus
920
+ installer with the following command:
921
+
922
+ $ bin/rails g solidus:install
923
+
924
+ If you are updating Solidus from an older version, please run
925
+ the following commands to complete the update:
926
+
927
+ $ bin/rails solidus:upgrade
928
+
929
+ Please report any issues at:
930
+ - https://github.com/solidusio/solidus/issues
931
+ - http://slack.solidus.io/
932
+ -------------------------------------------------------------
916
933
  rdoc_options: []
917
934
  require_paths:
918
935
  - lib
@@ -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
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :solidus do
4
- namespace :migrations do
5
- namespace :migrate_default_billing_addresses_to_address_book do
6
- task up: :environment do
7
- print "Migrating default billing addresses to address book ... "
8
- if Spree::UserAddress.where(default_billing: true).any?
9
- Spree::LegacyUser.joins(:bill_address).update_all(bill_address_id: nil) # rubocop:disable Rails/SkipsModelValidations
10
- end
11
- adapter_type = Spree::Base.connection.adapter_name.downcase.to_sym
12
- if adapter_type == :mysql2
13
- sql = <<~SQL
14
- UPDATE spree_user_addresses
15
- JOIN spree_users ON spree_user_addresses.user_id = spree_users.id
16
- AND spree_user_addresses.address_id = spree_users.bill_address_id
17
- SET spree_user_addresses.default_billing = true
18
- SQL
19
- else
20
- sql = <<~SQL
21
- UPDATE spree_user_addresses
22
- SET default_billing = true
23
- FROM spree_users
24
- WHERE spree_user_addresses.address_id = spree_users.bill_address_id
25
- AND spree_user_addresses.user_id = spree_users.id;
26
- SQL
27
- end
28
- Spree::Base.connection.execute sql
29
- puts "Success"
30
- end
31
-
32
- task down: :environment do
33
- Spree::UserAddress.update_all(default_billing: false) # rubocop:disable Rails/SkipsModelValidations
34
- puts "Rolled back default billing address migration to address book"
35
- end
36
- end
37
- end
38
- end