Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a configuration value for migration_path #4190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
12 changes: 11 additions & 1 deletion core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/migrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def app_migrations
end

def app_dir
"#{Rails.root}/db/migrate"
Spree::Config.migration_path
end

def engine_dir
Expand Down
20 changes: 20 additions & 0 deletions core/spec/lib/spree/app_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion core/spec/lib/spree/migrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down