solidus_act_as_tenant 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +62 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +1 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +21 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +5 -0
  9. data/CHANGELOG.md +3 -0
  10. data/Gemfile +47 -0
  11. data/LICENSE +26 -0
  12. data/README.md +100 -0
  13. data/Rakefile +7 -0
  14. data/app/decorators/spree/store_credit_decorator.rb +16 -0
  15. data/app/decorators/spree/variant_decorator.rb +22 -0
  16. data/app/models/spree/products_taxon.rb +9 -0
  17. data/app/models/spree/reimbursement_credit.rb +9 -0
  18. data/app/models/spree/tenant.rb +9 -0
  19. data/bin/console +17 -0
  20. data/bin/rails +7 -0
  21. data/bin/rails-engine +13 -0
  22. data/bin/rails-sandbox +16 -0
  23. data/bin/rake +7 -0
  24. data/bin/sandbox +76 -0
  25. data/bin/setup +8 -0
  26. data/config/locales/en.yml +4 -0
  27. data/config/routes.rb +5 -0
  28. data/db/migrate/20241204043609_add_tenant_id_to_solidus_tables.rb +100 -0
  29. data/db/migrate/20241204055845_update_spree_unique_indexes_with_tenant_scope.rb +17 -0
  30. data/db/migrate/20241204105318_create_spree_tenants.rb +15 -0
  31. data/lib/generators/solidus_act_as_tenant/install/install_generator.rb +38 -0
  32. data/lib/generators/solidus_act_as_tenant/install/templates/initializer.rb +8 -0
  33. data/lib/generators/solidus_act_as_tenant/install/templates/tenant_aware_models.yml +95 -0
  34. data/lib/solidus_act_as_tenant/configuration.rb +19 -0
  35. data/lib/solidus_act_as_tenant/engine.rb +23 -0
  36. data/lib/solidus_act_as_tenant/factories/preference_factory.rb +7 -0
  37. data/lib/solidus_act_as_tenant/factories/tenant_factory.rb +9 -0
  38. data/lib/solidus_act_as_tenant/tenant_aware.rb +50 -0
  39. data/lib/solidus_act_as_tenant/testing_support/factories.rb +5 -0
  40. data/lib/solidus_act_as_tenant/utils/tenant_selector.rb +74 -0
  41. data/lib/solidus_act_as_tenant/version.rb +5 -0
  42. data/lib/solidus_act_as_tenant.rb +8 -0
  43. data/solidus_act_as_tenant.gemspec +38 -0
  44. data/spec/lib/solidus_act_as_tenant/tenant_aware_spec.rb +48 -0
  45. data/spec/models/spree/store_credit_spec.rb +15 -0
  46. data/spec/models/spree/variant_spec.rb +37 -0
  47. data/spec/spec_helper.rb +32 -0
  48. data/spec/support/config.rb +21 -0
  49. metadata +177 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21133e1e0cc428fdca8a7c70108361c008834111cf0a16ff76d513808adf01cc
4
+ data.tar.gz: 4766840233045195d2449ff960ba1ebb8bd92eb55ac804c44b79ef2c238ae802
5
+ SHA512:
6
+ metadata.gz: 541ab0017f20b0bdf25268be074fb74882b10a74cd57361c6279a8eb7b7edf71bdd5a7277e7da707555967ec8b420df35c22f835618dc0d1422940f8a69d9353
7
+ data.tar.gz: 468b1a5c15e28faba9ab9f7a7da27b4047c463a42aea7e93fd4b7accfc604b12b2945a9cdfae5735d883dfba0e4646264bec4bbddced7609a26645c876bf3f5a
@@ -0,0 +1,62 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ browser-tools: circleci/browser-tools@1.1
5
+ solidusio_extensions: solidusio/extensions@volatile
6
+
7
+ jobs:
8
+ run-specs-with-sqlite:
9
+ executor:
10
+ name: solidusio_extensions/sqlite
11
+ ruby_version: '3.1'
12
+ steps:
13
+ - browser-tools/install-chrome
14
+ - solidusio_extensions/run-tests
15
+ run-specs-with-postgres:
16
+ executor:
17
+ name: solidusio_extensions/postgres
18
+ ruby_version: '3.1'
19
+ steps:
20
+ - browser-tools/install-chrome
21
+ - solidusio_extensions/run-tests
22
+ run-specs-with-mysql:
23
+ executor:
24
+ name: solidusio_extensions/mysql
25
+ ruby_version: '3.1'
26
+ steps:
27
+ - browser-tools/install-chrome
28
+ - solidusio_extensions/run-tests
29
+ lint-code:
30
+ executor:
31
+ name: solidusio_extensions/sqlite-memory
32
+ ruby_version: '3.1'
33
+ steps:
34
+ - solidusio_extensions/lint-code
35
+
36
+ workflows:
37
+ "Run specs on supported Solidus versions":
38
+ jobs:
39
+ - run-specs-with-sqlite:
40
+ context: acts_as_tenant
41
+ - run-specs-with-postgres:
42
+ context: acts_as_tenant
43
+ - run-specs-with-mysql:
44
+ context: acts_as_tenant
45
+ - lint-code:
46
+ context: acts_as_tenant
47
+
48
+ "Weekly run specs against main":
49
+ triggers:
50
+ - schedule:
51
+ cron: "0 0 * * 4" # every Thursday
52
+ filters:
53
+ branches:
54
+ only:
55
+ - main
56
+ jobs:
57
+ - run-specs-with-sqlite:
58
+ context: acts_as_tenant
59
+ - run-specs-with-postgres:
60
+ context: acts_as_tenant
61
+ - run-specs-with-mysql:
62
+ context: acts_as_tenant
data/.gem_release.yml ADDED
@@ -0,0 +1,5 @@
1
+ bump:
2
+ recurse: false
3
+ file: 'lib/solidus_act_as_tenant/version.rb'
4
+ message: Bump SolidusActAsTenant to %{version}
5
+ tag: true
data/.github/stale.yml ADDED
@@ -0,0 +1 @@
1
+ _extends: .github
@@ -0,0 +1,2 @@
1
+ issues=false
2
+ exclude-labels=infrastructure
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ \#*
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .sass-cache
9
+ coverage
10
+ Gemfile.lock
11
+ Gemfile-local
12
+ tmp
13
+ nbproject
14
+ pkg
15
+ *.swp
16
+ spec/dummy
17
+ spec/examples.txt
18
+ /sandbox
19
+ .rvmrc
20
+ .ruby-version
21
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ require:
2
+ - solidus_dev_support/rubocop
3
+
4
+ AllCops:
5
+ NewCops: disable
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Changelog
2
+
3
+ See https://github.com/solidusio-contrib/solidus_act_as_tenant/releases or OLD_CHANGELOG.md for older versions.
data/Gemfile ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
8
+
9
+ # The solidus_frontend gem has been pulled out since v3.2
10
+ if branch >= 'v3.2'
11
+ gem 'solidus_frontend'
12
+ elsif branch == 'main'
13
+ gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
14
+ else
15
+ gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
16
+ end
17
+
18
+ # Needed to help Bundler figure out how to resolve dependencies,
19
+ # otherwise it takes forever to resolve them.
20
+ # See https://github.com/bundler/bundler/issues/6677
21
+ gem 'rails', '>0.a'
22
+
23
+ # Provides basic authentication functionality for testing parts of your engine
24
+ gem 'solidus_auth_devise'
25
+
26
+ case ENV.fetch('DB', nil)
27
+ when 'mysql'
28
+ gem 'mysql2'
29
+ when 'postgresql'
30
+ gem 'pg'
31
+ else
32
+ gem 'sqlite3', '~> 1.4'
33
+ end
34
+
35
+ # While we still support Ruby < 3 we need to workaround a limitation in
36
+ # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
37
+ # resolve gems based on the required ruby version.
38
+ gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
39
+
40
+ gemspec
41
+
42
+ # Use a local Gemfile to include development dependencies that might not be
43
+ # relevant for the project or for other contributors, e.g. pry-byebug.
44
+ #
45
+ # We use `send` instead of calling `eval_gemfile` to work around an issue with
46
+ # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
47
+ send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2024 Solidus Contrib
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Solidus nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # Solidus Act As Tenant
2
+
3
+ [![CircleCI](https://dl.circleci.com/status-badge/img/gh/nebulab/solidus_acts_as_tenant/tree/Add-acts_as_tenant-to-Solidus.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/nebulab/solidus_acts_as_tenant/tree/Add-acts_as_tenant-to-Solidus)
4
+ [![codecov](https://codecov.io/gh/solidusio-contrib/solidus_act_as_tenant/branch/main/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_act_as_tenant)
5
+
6
+
7
+ This extension adds multi-tenant support to solidus using the row-level tenancy [acts_as_tenant](https://github.com/ErwinM/acts_as_tenant/commits/master/) gem.
8
+
9
+ It adds tenant scoping to a configurabale set of models and adds a console utility to switch between tenants.
10
+
11
+ ## Installation
12
+
13
+ Add solidus_act_as_tenant to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'solidus_act_as_tenant'
17
+ ```
18
+
19
+ Bundle your dependencies and run the installation generator:
20
+
21
+ ```shell
22
+ bin/rails generate solidus_act_as_tenant:install
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ See the [acts_as_tenant](https://github.com/ErwinM/acts_as_tenant) gem for an explanation of how tenant scoping works.
28
+
29
+ To configure this extension for your project, see:
30
+
31
+ - The generated migration files
32
+ - The generated tenant_aware_models.yml file
33
+ - The generated initializer.rb file
34
+
35
+
36
+ There is also a console utility that can be used to simply manage tenants in the console.
37
+ To use it, you can add it to your `~/.irbrc` file or `~/.pryrc` file:
38
+
39
+ ```ruby
40
+ if defined?(Rails)
41
+ TS = SolidusActAsTenant::Utils::TenantSelector.new
42
+
43
+ IRB.conf[:IRB_RC] = proc do
44
+ # * TS.ask => anytime in console, to switch tenant from a list
45
+ # * TS.current => same as Apartment::Tenant.current
46
+ # * TS.tenants => hash of tenants. Example: { 0 => "Demo Company" }
47
+ # * TS.switch_tenant!(tenant_name) => same as ActsAsTenant.current_tenant = Tenant.find_by(name: tenant_name)
48
+ TS.ask
49
+ end
50
+ end
51
+ ```
52
+
53
+ ## Development
54
+
55
+ ### Testing the extension
56
+
57
+ First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
58
+ app if it does not exist, then it will run specs. The dummy app can be regenerated by using
59
+ `bin/rake extension:test_app`.
60
+
61
+ ```shell
62
+ bin/rake
63
+ ```
64
+
65
+ To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run
66
+
67
+ ```shell
68
+ bundle exec rubocop
69
+ ```
70
+
71
+ When testing your application's integration with this extension you may use its factories.
72
+ You can load Solidus core factories along with this extension's factories using this statement:
73
+
74
+ ```ruby
75
+ SolidusDevSupport::TestingSupport::Factories.load_for(SolidusActAsTenant::Engine)
76
+ ```
77
+
78
+ ### Running the sandbox
79
+
80
+ To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
81
+ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
82
+ `sandbox/bin/rails`.
83
+
84
+ Here's an example:
85
+
86
+ ```
87
+ $ bin/rails server
88
+ => Booting Puma
89
+ => Rails 6.0.2.1 application starting in development
90
+ * Listening on tcp://127.0.0.1:3000
91
+ Use Ctrl-C to stop
92
+ ```
93
+
94
+ ### Releasing new versions
95
+
96
+ Please refer to the [dedicated page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) in the Solidus wiki.
97
+
98
+ ## License
99
+
100
+ Copyright (c) 2024 Solidus Contrib, released under the New BSD License.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require 'solidus_dev_support/rake_tasks'
5
+ SolidusDevSupport::RakeTasks.install
6
+
7
+ task default: 'extension:specs'
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusActAsTenant
4
+ module Spree
5
+ module StoreCreditDecorator
6
+ # Fixes no method error related to validations added through acts_as_tenant
7
+ def payment_method_id
8
+ super
9
+ rescue NoMethodError
10
+ nil
11
+ end
12
+
13
+ ::Spree::StoreCredit.prepend(self)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusActAsTenant
4
+ module Spree
5
+ module VariantDecorator
6
+ # Fixes no method error related to validations added through acts_as_tenant
7
+ def shipping_category_id
8
+ super
9
+ rescue NoMethodError
10
+ product && product_shipping_category_id
11
+ end
12
+
13
+ def shipping_category
14
+ super
15
+ rescue NoMethodError
16
+ product && product_shipping_category
17
+ end
18
+
19
+ ::Spree::Variant.prepend(self)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class ProductsTaxon < Spree::Base
5
+ acts_as_tenant :tenant
6
+ belongs_to :product
7
+ belongs_to :taxon
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class ReimbursementCredit < Spree::Base
5
+ acts_as_tenant :tenant
6
+ belongs_to :reimbursement
7
+ belongs_to :creditable, polymorphic: true
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class Tenant < Spree::Base
5
+ validates :name, presence: true, uniqueness: true
6
+ validates :subdomain, uniqueness: true
7
+ validates :domain, uniqueness: true
8
+ end
9
+ end
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_act_as_tenant"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/rails ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if %w[g generate].include? ARGV.first
4
+ exec "#{__dir__}/rails-engine", *ARGV
5
+ else
6
+ exec "#{__dir__}/rails-sandbox", *ARGV
7
+ end
data/bin/rails-engine ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/solidus_act_as_tenant/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
data/bin/rails-sandbox ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = 'sandbox'
4
+
5
+ unless File.exist? "#{app_root}/bin/rails"
6
+ warn 'Creating the sandbox app...'
7
+ Dir.chdir "#{__dir__}/.." do
8
+ system "#{__dir__}/sandbox" or begin
9
+ warn 'Automatic creation of the sandbox app failed'
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir.chdir app_root
16
+ exec 'bin/rails', *ARGV
data/bin/rake ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rake", "rake")
data/bin/sandbox ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+ test -z "${DEBUG+empty_string}" || set -x
5
+
6
+ test "$DB" = "sqlite" && export DB="sqlite3"
7
+
8
+ if [ -z "$PAYMENT_METHOD" ]
9
+ then
10
+ PAYMENT_METHOD="none"
11
+ fi
12
+
13
+ if [ -z "$SOLIDUS_BRANCH" ]
14
+ then
15
+ echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch"
16
+ SOLIDUS_BRANCH="main"
17
+ fi
18
+ echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
19
+
20
+ extension_name="solidus_act_as_tenant"
21
+
22
+ # Stay away from the bundler env of the containing extension.
23
+ function unbundled {
24
+ ruby -rbundler -e'
25
+ Bundler.with_unbundled_env {system *ARGV}' -- \
26
+ env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
27
+ }
28
+
29
+ echo "~~~> Removing the old sandbox"
30
+ rm -rf ./sandbox
31
+
32
+ echo "~~~> Creating a pristine Rails app"
33
+ rails new sandbox \
34
+ --database="${DB:-sqlite3}" \
35
+ --skip-git \
36
+ --skip-keeps \
37
+ --skip-rc \
38
+ --skip-bootsnap \
39
+ --skip-test
40
+
41
+ if [ ! -d "sandbox" ]; then
42
+ echo 'sandbox rails application failed'
43
+ exit 1
44
+ fi
45
+
46
+ echo "~~~> Adding solidus (with i18n) to the Gemfile"
47
+ cd ./sandbox
48
+ cat <<RUBY >> Gemfile
49
+ gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
50
+ gem 'rails-i18n'
51
+ gem 'solidus_i18n'
52
+ gem 'solidus_auth_devise'
53
+
54
+ gem '$extension_name', path: '..'
55
+
56
+ group :test, :development do
57
+ platforms :mri do
58
+ gem 'pry-byebug'
59
+ end
60
+ end
61
+ RUBY
62
+
63
+ unbundled bundle install --gemfile Gemfile
64
+
65
+ unbundled bundle exec rake db:drop db:create
66
+
67
+ unbundled bundle exec rails generate solidus:install \
68
+ --auto-accept \
69
+ $@
70
+
71
+ unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
72
+ unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
73
+
74
+ echo
75
+ echo "🚀 Sandbox app successfully created for $extension_name!"
76
+ echo "🧪 This app is intended for test purposes."
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bin/rake clobber
@@ -0,0 +1,4 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Core::Engine.routes.draw do
4
+ # Add your extension routes here
5
+ end
@@ -0,0 +1,100 @@
1
+ class AddTenantIdToSolidusTables < ActiveRecord::Migration[7.0]
2
+ # These are tables that don't need a tenancy but may be desired:
3
+ # spree_countries (also remove "iso" uniqueness index)
4
+ # spree_states
5
+ # spree_permission_sets
6
+ # spree_roles (also remove "name" uniqueness index)
7
+ # spree_role_permissions
8
+
9
+ TABLES = %w[
10
+ spree_addresses
11
+ spree_adjustments
12
+ spree_credit_cards
13
+ spree_payments
14
+ spree_refunds
15
+ spree_roles_users
16
+ spree_shipping_method_categories
17
+ spree_store_credit_types
18
+ spree_store_credits
19
+ spree_calculators
20
+ spree_users
21
+ spree_adjustment_reasons
22
+ spree_assets
23
+ spree_cartons
24
+ spree_customer_returns
25
+ spree_inventory_units
26
+ spree_line_item_actions
27
+ spree_line_items
28
+ spree_log_entries
29
+ spree_option_type_prototypes
30
+ spree_option_types
31
+ spree_option_values
32
+ spree_option_values_variants
33
+ spree_orders
34
+ spree_payment_capture_events
35
+ spree_payment_methods
36
+ spree_preferences
37
+ spree_prices
38
+ spree_product_option_types
39
+ spree_product_properties
40
+ spree_products
41
+ spree_products_taxons
42
+ spree_properties
43
+ spree_property_prototypes
44
+ spree_prototype_taxons
45
+ spree_prototypes
46
+ spree_refund_reasons
47
+ spree_reimbursement_credits
48
+ spree_reimbursement_types
49
+ spree_reimbursements
50
+ spree_return_authorizations
51
+ spree_return_items
52
+ spree_return_reasons
53
+ spree_shipments
54
+ spree_shipping_categories
55
+ spree_shipping_method_stock_locations
56
+ spree_shipping_method_zones
57
+ spree_shipping_methods
58
+ spree_shipping_rate_taxes
59
+ spree_shipping_rates
60
+ spree_state_changes
61
+ spree_stock_items
62
+ spree_stock_locations
63
+ spree_stock_movements
64
+ spree_store_credit_categories
65
+ spree_store_credit_events
66
+ spree_store_payment_methods
67
+ spree_stores
68
+ spree_store_shipping_methods
69
+ spree_store_credit_reasons
70
+ spree_tax_categories
71
+ spree_tax_rates
72
+ spree_taxonomies
73
+ spree_taxons
74
+ spree_tax_rate_tax_categories
75
+ spree_unit_cancels
76
+ spree_user_addresses
77
+ spree_user_stock_locations
78
+ spree_variant_property_rule_conditions
79
+ spree_variant_property_rule_values
80
+ spree_variant_property_rules
81
+ spree_variants
82
+ spree_wallet_payment_sources
83
+ spree_zone_members
84
+ spree_zones
85
+ ].push(::Spree.user_class.table_name).uniq.freeze
86
+
87
+ def up
88
+ TABLES.each do |table|
89
+ add_column table, :tenant_id, :bigint
90
+ add_index table, :tenant_id
91
+ end
92
+ end
93
+
94
+ def down
95
+ TABLES.each do |table|
96
+ remove_index table
97
+ remove_column table, :tenant_id
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,17 @@
1
+ class UpdateSpreeUniqueIndexesWithTenantScope < ActiveRecord::Migration[7.0]
2
+ def up
3
+ remove_index :spree_preferences, name: :index_spree_preferences_on_key
4
+ remove_index :spree_products, name: :index_spree_products_on_slug
5
+
6
+ add_index :spree_preferences, %i[tenant_id key], unique: true, name: :index_spree_preferences_on_tenant_and_key
7
+ add_index :spree_products, %i[tenant_id slug], unique: true, name: :index_spree_products_on_tenant_and_slug
8
+ end
9
+
10
+ def down
11
+ remove_index :spree_preferences, name: :index_spree_preferences_on_tenant_and_key
12
+ remove_index :spree_products, name: :index_spree_products_on_tenant_and_slug
13
+
14
+ add_index :spree_preferences, :key, unique: true, name: :index_spree_preferences_on_key
15
+ add_index :spree_products, :slug, unique: true, name: :index_spree_products_on_slug
16
+ end
17
+ end