diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3755ce545..70e36549fc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Solidus 3.2.0.alpha (master, unreleased) +### Core + +- Add configuration option for `migration_path` [#4190](https://github.com/solidusio/solidus/pull/4190) ([SuperGoodSoft](https://github.com/supergoodsoft/)) + ## Solidus 3.1.1 (v3.1, 2021-09-20) - Add deprecation path for arity-zero preference defaults [#4170](https://github.com/solidusio/solidus/pull/4170) ([waiting-for-dev](https://github.com/waiting-for-dev)) diff --git a/core/lib/spree/app_configuration.rb b/core/lib/spree/app_configuration.rb index e0276aa5ac1..d167d0c83f2 100644 --- a/core/lib/spree/app_configuration.rb +++ b/core/lib/spree/app_configuration.rb @@ -263,7 +263,6 @@ class AppConfiguration < Preferences::Configuration # @return [] Track on_hand values for variants / products. (default: true) preference :track_inventory_levels, :boolean, default: true - # Other configurations # Allows restricting what currencies will be available. @@ -525,6 +524,17 @@ def payment_canceller # Enumerable of taxons adhering to the present_taxon_class interface class_name_attribute :taxon_attachment_module, default: 'Spree::Taxon::ActiveStorageAttachment' + # Configures the absolute path that contains the Solidus engine + # migrations. This will be checked at app boot to confirm that all Solidus + # migrations are installed. + # + # @!attribute [rw] migration_path + # @return [Pathname] the configured path. (default: `Rails.root.join('db', 'migrate')`) + attr_writer :migration_path + def migration_path + @migration_path ||= ::Rails.root.join('db', 'migrate') + end + # Allows providing your own class instance for generating order numbers. # # @!attribute [rw] order_number_generator diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb index 1055a58d322..a42590f1cf3 100644 --- a/core/lib/spree/core/engine.rb +++ b/core/lib/spree/core/engine.rb @@ -40,7 +40,7 @@ class Engine < ::Rails::Engine ] end - initializer "spree.core.checking_migrations", before: :load_config_initializers do |_app| + initializer "spree.core.checking_migrations", after: :load_config_initializers do |_app| Migrations.new(config, engine_name).check end diff --git a/core/lib/spree/migrations.rb b/core/lib/spree/migrations.rb index 63a05a21956..340ba31343b 100644 --- a/core/lib/spree/migrations.rb +++ b/core/lib/spree/migrations.rb @@ -66,7 +66,7 @@ def app_migrations end def app_dir - "#{Rails.root}/db/migrate" + Spree::Config.migration_path end def engine_dir diff --git a/core/spec/lib/spree/app_configuration_spec.rb b/core/spec/lib/spree/app_configuration_spec.rb index 58a9360d6e7..5296419e6fc 100644 --- a/core/spec/lib/spree/app_configuration_spec.rb +++ b/core/spec/lib/spree/app_configuration_spec.rb @@ -129,6 +129,26 @@ class DummyClass; end; end end + describe "#migration_path" do + subject { config_instance.migration_path } + + let(:config_instance) { described_class.new } + + it "has a default value" do + expect(subject.to_s).to end_with "db/migrate" + end + + context "with a custom value" do + before do + config_instance.migration_path = "db/secondary_database" + end + + it "returns the configured value" do + expect(subject).to eq "db/secondary_database" + end + end + end + it 'has a default admin VAT location with nil values by default' do expect(prefs.admin_vat_location).to eq(Spree::Tax::TaxLocation.new) expect(prefs.admin_vat_location.state_id).to eq(nil) diff --git a/core/spec/lib/spree/migrations_spec.rb b/core/spec/lib/spree/migrations_spec.rb index 0b6a0817d6c..5aa67450e8d 100644 --- a/core/spec/lib/spree/migrations_spec.rb +++ b/core/spec/lib/spree/migrations_spec.rb @@ -10,10 +10,14 @@ module Spree let(:config) { double("Config", root: "dir") } let(:engine_dir) { "dir/db/migrate" } - let(:app_dir) { "#{Rails.root}/db/migrate" } + let(:app_dir) { 'app/db/migrate' } subject { described_class.new(config, "spree") } + before do + stub_spree_preferences(migration_path: app_dir) + end + it "detects missing migrations" do expect(Dir).to receive(:entries).with(app_dir).and_return app_migrations expect(Dir).to receive(:entries).with(engine_dir).and_return engine_migrations