ros-apartment 2.8.1.rc2 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4eae53ab581ffa6402db4640424f23f864b8a4f72a1cf38bd35dc200fc014bf
4
- data.tar.gz: f0ca3c1ae5102e4aa644aab5758543032455d6266fc86c5b3d97bb6e21eab731
3
+ metadata.gz: 6182f5dcd4e369e6f497295705079b3d0b20d644d8006c5a256d8618eff1a2c3
4
+ data.tar.gz: 351be335f73230dd83df3020ba77b33f8e33e297f67c5256210f3e0c0c12e749
5
5
  SHA512:
6
- metadata.gz: f4bca612be122515d41ab388cf1bc22d96216b0baa8178a6d6d1a52418c932bcafe97f4089dfc1eff3725544ee1044391772f35935b86caf67c66d311e85c7ac
7
- data.tar.gz: fb489d69d50d6caea7c3a19be53b8e693fb8ea24782c8850eb4efca070eecce7364f3f2fc7d8f17a37e93caeed6a08ef6cfad3dbd7c47857c91442803e44e51c
6
+ metadata.gz: 7714a5182a47cefc6a95d85118278263bf4d326c5441184005a3ef48cf10368cd123602a0e5635547233c12ecb587e107dc72c0a117423dd774054f19767e3ce
7
+ data.tar.gz: 6b4247215b4754d031ce248f6e457d1c509157d310964e74cc72f05e8f896215b29341cd892515c9e9803a2f0db6528f180474b0c14cf03384ee1ac4f9693164
data/.circleci/config.yml CHANGED
@@ -1,8 +1,5 @@
1
1
  version: 2.1
2
2
 
3
- orbs:
4
- rubocop: hanachin/rubocop@0.0.6
5
-
6
3
  jobs:
7
4
  build:
8
5
  docker:
@@ -61,7 +58,10 @@ jobs:
61
58
 
62
59
  - run:
63
60
  name: Run tests
64
- command: bundle exec rspec
61
+ command: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/test-results/rspec/rspec.xml
62
+
63
+ - store_test_results:
64
+ path: ~/test-results/rspec/
65
65
 
66
66
  workflows:
67
67
  tests:
@@ -69,10 +69,10 @@ workflows:
69
69
  - build:
70
70
  matrix:
71
71
  parameters:
72
- ruby_version: ["ruby:2.6-buster", "ruby:2.7-buster"]
73
- gemfile: ["gemfiles/rails_5_2.gemfile", "gemfiles/rails_6_0.gemfile"]
74
-
75
- rubocop:
76
- jobs:
77
- - rubocop/rubocop:
78
- version: 0.88.0
72
+ ruby_version: ["ruby:2.6-buster", "ruby:2.7-buster", "ruby:3.0-buster"]
73
+ gemfile: ["gemfiles/rails_5_2.gemfile", "gemfiles/rails_6_0.gemfile", "gemfiles/rails_6_1.gemfile", "gemfiles/rails_7_0.gemfile"]
74
+ exclude:
75
+ - ruby_version: "ruby:3.0-buster"
76
+ gemfile: "gemfiles/rails_5_2.gemfile"
77
+ - ruby_version: "ruby:2.6-buster"
78
+ gemfile: "gemfiles/rails_7_0.gemfile"
@@ -0,0 +1,22 @@
1
+ name: reviewdog
2
+ on: [push, pull_request]
3
+ jobs:
4
+ rubocop:
5
+ name: runner / rubocop
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Check out code
9
+ uses: actions/checkout@v2
10
+ - name: Read ruby version
11
+ run: echo ::set-output name=RUBY_VERSION::$(cat .ruby-version | cut -f 1,2 -d .)
12
+ id: rv
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: "${{ steps.rv.outputs.RUBY_VERSION }}"
16
+ - uses: reviewdog/action-rubocop@v1
17
+ with:
18
+ filter_mode: nofilter
19
+ reporter: github-check
20
+ rubocop_version: 0.93.1
21
+ github_token: ${{ secrets.github_token }}
22
+ rubocop_extensions: rubocop-performance:1.10.2 rubocop-rails:2.9.1 rubocop-rspec:1.44.1
data/.rubocop.yml CHANGED
@@ -1,96 +1,32 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
- AllCops:
4
- Exclude:
5
- - 'gemfiles/**/*.gemfile'
6
- - 'gemfiles/vendor/**/*'
7
- - 'spec/dummy_engine/dummy_engine.gemspec'
8
-
9
- Gemspec/RequiredRubyVersion:
10
- Exclude:
11
- - 'ros-apartment.gemspec'
3
+ require:
4
+ - rubocop-rails
5
+ - rubocop-performance
6
+ - rubocop-rspec
12
7
 
13
- Style/WordArray:
8
+ AllCops:
14
9
  Exclude:
10
+ - gemfiles/**/*.gemfile
11
+ - gemfiles/vendor/**/*
12
+ - spec/dummy_engine/dummy_engine.gemspec
15
13
  - spec/schemas/**/*.rb
16
14
 
17
- Style/NumericLiterals:
18
- Exclude:
19
- - spec/schemas/**/*.rb
15
+ NewCops: enable
20
16
 
21
- Layout/EmptyLineAfterMagicComment:
17
+ Gemspec/RequiredRubyVersion:
22
18
  Exclude:
23
- - spec/schemas/**/*.rb
19
+ - 'ros-apartment.gemspec'
24
20
 
25
21
  Metrics/BlockLength:
26
22
  Exclude:
27
23
  - spec/**/*.rb
28
24
 
29
- Layout/EmptyLinesAroundAttributeAccessor:
30
- Enabled: true
31
-
32
- Layout/SpaceAroundMethodCallOperator:
33
- Enabled: true
34
-
35
- Lint/DeprecatedOpenSSLConstant:
36
- Enabled: true
37
-
38
- Lint/DuplicateElsifCondition:
39
- Enabled: true
40
-
41
- Lint/MixedRegexpCaptureTypes:
42
- Enabled: true
43
-
44
- Lint/RaiseException:
45
- Enabled: true
46
-
47
- Lint/StructNewOverride:
48
- Enabled: true
49
-
50
- Style/AccessorGrouping:
51
- Enabled: true
52
-
53
- Style/ArrayCoercion:
54
- Enabled: true
55
-
56
- Style/BisectedAttrAccessor:
57
- Enabled: true
58
-
59
- Style/CaseLikeIf:
60
- Enabled: true
61
-
62
- Style/ExponentialNotation:
63
- Enabled: true
64
-
65
- Style/HashAsLastArrayItem:
66
- Enabled: true
67
-
68
- Style/HashEachMethods:
69
- Enabled: true
70
-
71
- Style/HashLikeCase:
72
- Enabled: true
73
-
74
- Style/HashTransformKeys:
75
- Enabled: true
76
-
77
- Style/HashTransformValues:
78
- Enabled: true
79
-
80
- Style/RedundantAssignment:
81
- Enabled: true
82
-
83
- Style/RedundantFetchBlock:
84
- Enabled: true
85
-
86
- Style/RedundantFileExtensionInRequire:
87
- Enabled: true
88
-
89
- Style/RedundantRegexpCharacterClass:
90
- Enabled: true
25
+ Rails/RakeEnvironment:
26
+ Enabled: false
91
27
 
92
- Style/RedundantRegexpEscape:
93
- Enabled: true
28
+ Rails/ApplicationRecord:
29
+ Enabled: false
94
30
 
95
- Style/SlicingWithRange:
96
- Enabled: true
31
+ Rails/Output:
32
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-07-16 04:15:41 UTC using RuboCop version 0.88.0.
3
+ # on 2021-06-26 03:25:28 UTC using RuboCop version 0.93.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -11,22 +11,16 @@ Lint/MixedRegexpCaptureTypes:
11
11
  Exclude:
12
12
  - 'lib/apartment/elevators/domain.rb'
13
13
 
14
- # Offense count: 2
15
- # Cop supports --auto-correct.
16
- Lint/NonDeterministicRequireOrder:
17
- Exclude:
18
- - 'spec/spec_helper.rb'
19
-
20
- # Offense count: 7
14
+ # Offense count: 3
21
15
  # Configuration parameters: IgnoredMethods.
22
16
  Metrics/AbcSize:
23
- Max: 33
17
+ Max: 28
24
18
 
25
- # Offense count: 3
19
+ # Offense count: 5
26
20
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
27
21
  # ExcludedMethods: refine
28
22
  Metrics/BlockLength:
29
- Max: 102
23
+ Max: 83
30
24
 
31
25
  # Offense count: 1
32
26
  # Configuration parameters: CountComments, CountAsOne.
@@ -38,6 +32,188 @@ Metrics/ClassLength:
38
32
  Metrics/MethodLength:
39
33
  Max: 24
40
34
 
35
+ # Offense count: 3
36
+ RSpec/AnyInstance:
37
+ Exclude:
38
+ - 'spec/unit/migrator_spec.rb'
39
+
40
+ # Offense count: 2
41
+ RSpec/BeforeAfterAll:
42
+ Exclude:
43
+ - 'spec/spec_helper.rb'
44
+ - 'spec/rails_helper.rb'
45
+ - 'spec/support/**/*.rb'
46
+ - 'spec/adapters/sqlite3_adapter_spec.rb'
47
+ - 'spec/tasks/apartment_rake_spec.rb'
48
+
49
+ # Offense count: 18
50
+ # Configuration parameters: Prefixes.
51
+ # Prefixes: when, with, without
52
+ RSpec/ContextWording:
53
+ Exclude:
54
+ - 'spec/adapters/sqlite3_adapter_spec.rb'
55
+ - 'spec/examples/generic_adapter_custom_configuration_example.rb'
56
+ - 'spec/examples/schema_adapter_examples.rb'
57
+ - 'spec/support/contexts.rb'
58
+ - 'spec/tasks/apartment_rake_spec.rb'
59
+ - 'spec/tenant_spec.rb'
60
+
61
+ # Offense count: 4
62
+ # Configuration parameters: IgnoredMetadata.
63
+ RSpec/DescribeClass:
64
+ Exclude:
65
+ - 'spec/integration/apartment_rake_integration_spec.rb'
66
+ - 'spec/integration/query_caching_spec.rb'
67
+ - 'spec/integration/use_within_an_engine_spec.rb'
68
+ - 'spec/tasks/apartment_rake_spec.rb'
69
+
70
+ # Offense count: 12
71
+ # Cop supports --auto-correct.
72
+ # Configuration parameters: SkipBlocks, EnforcedStyle.
73
+ # SupportedStyles: described_class, explicit
74
+ RSpec/DescribedClass:
75
+ Exclude:
76
+ - 'spec/apartment_spec.rb'
77
+ - 'spec/tenant_spec.rb'
78
+ - 'spec/unit/elevators/host_hash_spec.rb'
79
+ - 'spec/unit/migrator_spec.rb'
80
+
81
+ # Offense count: 5
82
+ # Cop supports --auto-correct.
83
+ RSpec/EmptyLineAfterFinalLet:
84
+ Exclude:
85
+ - 'spec/adapters/sqlite3_adapter_spec.rb'
86
+ - 'spec/examples/schema_adapter_examples.rb'
87
+
88
+ # Offense count: 14
89
+ # Configuration parameters: Max.
90
+ RSpec/ExampleLength:
91
+ Exclude:
92
+ - 'spec/examples/generic_adapter_custom_configuration_example.rb'
93
+ - 'spec/examples/generic_adapter_examples.rb'
94
+ - 'spec/examples/schema_adapter_examples.rb'
95
+ - 'spec/integration/query_caching_spec.rb'
96
+ - 'spec/tenant_spec.rb'
97
+
98
+ # Offense count: 60
99
+ # Cop supports --auto-correct.
100
+ # Configuration parameters: CustomTransform, IgnoredWords.
101
+ RSpec/ExampleWording:
102
+ Exclude:
103
+ - 'spec/adapters/sqlite3_adapter_spec.rb'
104
+ - 'spec/apartment_spec.rb'
105
+ - 'spec/examples/connection_adapter_examples.rb'
106
+ - 'spec/examples/generic_adapter_custom_configuration_example.rb'
107
+ - 'spec/examples/generic_adapter_examples.rb'
108
+ - 'spec/examples/schema_adapter_examples.rb'
109
+ - 'spec/integration/apartment_rake_integration_spec.rb'
110
+ - 'spec/integration/use_within_an_engine_spec.rb'
111
+ - 'spec/tasks/apartment_rake_spec.rb'
112
+ - 'spec/tenant_spec.rb'
113
+
114
+ # Offense count: 13
115
+ # Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly.
116
+ RSpec/FilePath:
117
+ Exclude:
118
+ - 'spec/adapters/mysql2_adapter_spec.rb'
119
+ - 'spec/adapters/postgresql_adapter_spec.rb'
120
+ - 'spec/adapters/sqlite3_adapter_spec.rb'
121
+ - 'spec/tenant_spec.rb'
122
+ - 'spec/unit/config_spec.rb'
123
+ - 'spec/unit/elevators/domain_spec.rb'
124
+ - 'spec/unit/elevators/first_subdomain_spec.rb'
125
+ - 'spec/unit/elevators/generic_spec.rb'
126
+ - 'spec/unit/elevators/host_hash_spec.rb'
127
+ - 'spec/unit/elevators/host_spec.rb'
128
+ - 'spec/unit/elevators/subdomain_spec.rb'
129
+ - 'spec/unit/migrator_spec.rb'
130
+
131
+ # Offense count: 1
132
+ # Cop supports --auto-correct.
133
+ # Configuration parameters: EnforcedStyle.
134
+ # SupportedStyles: implicit, each, example
135
+ RSpec/HookArgument:
136
+ Exclude:
137
+ - 'spec/support/setup.rb'
138
+
139
+ # Offense count: 4
140
+ # Cop supports --auto-correct.
141
+ RSpec/HooksBeforeExamples:
142
+ Exclude:
143
+ - 'spec/adapters/sqlite3_adapter_spec.rb'
144
+ - 'spec/examples/schema_adapter_examples.rb'
145
+
146
+ # Offense count: 18
147
+ # Configuration parameters: AssignmentOnly.
148
+ RSpec/InstanceVariable:
149
+ Exclude:
150
+ - 'spec/examples/generic_adapter_examples.rb'
151
+ - 'spec/examples/schema_adapter_examples.rb'
152
+ - 'spec/integration/apartment_rake_integration_spec.rb'
153
+ - 'spec/integration/use_within_an_engine_spec.rb'
154
+ - 'spec/tasks/apartment_rake_spec.rb'
155
+
156
+ # Offense count: 1
157
+ # Cop supports --auto-correct.
158
+ RSpec/LeadingSubject:
159
+ Exclude:
160
+
161
+ # Offense count: 2
162
+ RSpec/LeakyConstantDeclaration:
163
+ Exclude:
164
+ - 'spec/examples/generic_adapters_callbacks_examples.rb'
165
+ - 'spec/unit/elevators/generic_spec.rb'
166
+
167
+ # Offense count: 35
168
+ # Configuration parameters: EnforcedStyle.
169
+ # SupportedStyles: have_received, receive
170
+ RSpec/MessageSpies:
171
+ Exclude:
172
+ - 'spec/examples/generic_adapter_custom_configuration_example.rb'
173
+ - 'spec/integration/apartment_rake_integration_spec.rb'
174
+ - 'spec/integration/use_within_an_engine_spec.rb'
175
+ - 'spec/tasks/apartment_rake_spec.rb'
176
+ - 'spec/unit/elevators/domain_spec.rb'
177
+ - 'spec/unit/elevators/generic_spec.rb'
178
+ - 'spec/unit/elevators/host_hash_spec.rb'
179
+ - 'spec/unit/elevators/host_spec.rb'
180
+ - 'spec/unit/elevators/subdomain_spec.rb'
181
+ - 'spec/unit/migrator_spec.rb'
182
+
183
+ # Offense count: 29
184
+ RSpec/MultipleExpectations:
185
+ Max: 4
186
+
187
+ # Offense count: 47
188
+ # Configuration parameters: IgnoreSharedExamples.
189
+ RSpec/NamedSubject:
190
+ Exclude:
191
+ - 'spec/adapters/mysql2_adapter_spec.rb'
192
+ - 'spec/adapters/sqlite3_adapter_spec.rb'
193
+ - 'spec/support/contexts.rb'
194
+ - 'spec/support/requirements.rb'
195
+ - 'spec/tenant_spec.rb'
196
+
197
+ # Offense count: 24
198
+ RSpec/NestedGroups:
199
+ Max: 5
200
+
201
+ # Offense count: 6
202
+ # Cop supports --auto-correct.
203
+ # Configuration parameters: EnforcedStyle.
204
+ # SupportedStyles: and_return, block
205
+ RSpec/ReturnFromStub:
206
+ Exclude:
207
+ - 'spec/integration/apartment_rake_integration_spec.rb'
208
+ - 'spec/unit/migrator_spec.rb'
209
+
210
+ # Offense count: 4
211
+ # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
212
+ RSpec/VerifiedDoubles:
213
+ Exclude:
214
+ - 'spec/integration/apartment_rake_integration_spec.rb'
215
+ - 'spec/unit/elevators/first_subdomain_spec.rb'
216
+
41
217
  # Offense count: 17
42
218
  Style/Documentation:
43
219
  Exclude:
@@ -52,15 +228,6 @@ Style/Documentation:
52
228
  - 'lib/apartment/migrator.rb'
53
229
  - 'lib/apartment/model.rb'
54
230
  - 'lib/apartment/railtie.rb'
55
- - 'lib/apartment/reloader.rb'
56
231
  - 'lib/apartment/tasks/enhancements.rb'
57
232
  - 'lib/apartment/tasks/task_helper.rb'
58
233
  - 'lib/generators/apartment/install/install_generator.rb'
59
-
60
- # Offense count: 3
61
- # Cop supports --auto-correct.
62
- Style/IfUnlessModifier:
63
- Exclude:
64
- - 'Rakefile'
65
- - 'lib/apartment.rb'
66
- - 'lib/apartment/tenant.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.5
data/Appraisals CHANGED
@@ -1,29 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'rails-5-0' do
4
- gem 'rails', '~> 5.0.0'
5
- platforms :ruby do
6
- gem 'pg', '< 1.0.0'
7
- end
8
- platforms :jruby do
9
- gem 'activerecord-jdbc-adapter', '~> 50.0'
10
- gem 'activerecord-jdbcpostgresql-adapter', '~> 50.0'
11
- gem 'activerecord-jdbcmysql-adapter', '~> 50.0'
12
- end
13
- end
14
-
15
- appraise 'rails-5-1' do
16
- gem 'rails', '~> 5.1.0'
17
- platforms :ruby do
18
- gem 'pg', '< 1.0.0'
19
- end
20
- platforms :jruby do
21
- gem 'activerecord-jdbc-adapter', '~> 51.0'
22
- gem 'activerecord-jdbcpostgresql-adapter', '~> 51.0'
23
- gem 'activerecord-jdbcmysql-adapter', '~> 51.0'
24
- end
25
- end
26
-
27
3
  appraise 'rails-5-2' do
28
4
  gem 'rails', '~> 5.2.0'
29
5
  platforms :jruby do
@@ -45,14 +21,38 @@ appraise 'rails-6-0' do
45
21
  end
46
22
  end
47
23
 
24
+ appraise 'rails-6-1' do
25
+ gem 'rails', '~> 6.1.0'
26
+ platforms :ruby do
27
+ gem 'sqlite3', '~> 1.4'
28
+ end
29
+ platforms :jruby do
30
+ gem 'activerecord-jdbc-adapter', '~> 61.0'
31
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 61.0'
32
+ gem 'activerecord-jdbcmysql-adapter', '~> 61.0'
33
+ end
34
+ end
35
+
36
+ appraise 'rails-7-0' do
37
+ gem 'rails', '~> 7.0.0'
38
+ platforms :ruby do
39
+ gem 'sqlite3', '~> 1.4'
40
+ end
41
+ platforms :jruby do
42
+ gem 'activerecord-jdbc-adapter', '~> 61.0'
43
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 61.0'
44
+ gem 'activerecord-jdbcmysql-adapter', '~> 61.0'
45
+ end
46
+ end
47
+
48
48
  appraise 'rails-master' do
49
49
  gem 'rails', git: 'https://github.com/rails/rails.git'
50
50
  platforms :ruby do
51
51
  gem 'sqlite3', '~> 1.4'
52
52
  end
53
53
  platforms :jruby do
54
- gem 'activerecord-jdbc-adapter', '~> 52.0'
55
- gem 'activerecord-jdbcpostgresql-adapter', '~> 52.0'
56
- gem 'activerecord-jdbcmysql-adapter', '~> 52.0'
54
+ gem 'activerecord-jdbc-adapter', '~> 61.0'
55
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 61.0'
56
+ gem 'activerecord-jdbcmysql-adapter', '~> 61.0'
57
57
  end
58
58
  end
data/Gemfile CHANGED
@@ -3,11 +3,3 @@
3
3
  source 'http://rubygems.org'
4
4
 
5
5
  gemspec
6
-
7
- gem 'rails', '>= 3.1.2'
8
- gem 'rubocop'
9
-
10
- group :local do
11
- gem 'guard-rspec', '~> 4.2'
12
- gem 'pry'
13
- end
data/README.md CHANGED
@@ -101,6 +101,16 @@ switched back at the end of the block to what it was before.
101
101
  There is also `switch!` which doesn't take a block, but it's recommended to use `switch`.
102
102
  To return to the default tenant, you can call `switch` with no arguments.
103
103
 
104
+ #### Multiple Tenants
105
+
106
+ When using schemas, you can also pass in a list of schemas if desired. Any tables defined in a schema earlier in the chain will be referenced first, so this is only useful if you have a schema with only some of the tables defined:
107
+
108
+ ```ruby
109
+ Apartment::Tenant.switch(['tenant_1', 'tenant_2']) do
110
+ # ...
111
+ end
112
+ ```
113
+
104
114
  ### Switching Tenants per request
105
115
 
106
116
  You can have Apartment route to the appropriate tenant by adding some Rack middleware.
@@ -334,7 +344,7 @@ Setting this configuration value to `false` will disable the schema presence che
334
344
 
335
345
  ```ruby
336
346
  Apartment.configure do |config|
337
- tenant_presence_check = false
347
+ config.tenant_presence_check = false
338
348
  end
339
349
  ```
340
350
 
@@ -3,12 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.2.0"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
6
 
13
7
  platforms :jruby do
14
8
  gem "activerecord-jdbc-adapter", "~> 52.0"
@@ -3,12 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.0.0"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
6
 
13
7
  platforms :ruby do
14
8
  gem "sqlite3", "~> 1.4"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+
7
+ platforms :ruby do
8
+ gem "sqlite3", "~> 1.4"
9
+ end
10
+
11
+ platforms :jruby do
12
+ gem "activerecord-jdbc-adapter", "~> 61.0"
13
+ gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
14
+ gem "activerecord-jdbcmysql-adapter", "~> 61.0"
15
+ end
16
+
17
+ gemspec path: "../"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 7.0.0"
6
+
7
+ platforms :ruby do
8
+ gem "sqlite3", "~> 1.4"
9
+ end
10
+
11
+ platforms :jruby do
12
+ gem "activerecord-jdbc-adapter", "~> 61.0"
13
+ gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
14
+ gem "activerecord-jdbcmysql-adapter", "~> 61.0"
15
+ end
16
+
17
+ gemspec path: "../"
@@ -3,21 +3,15 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", git: "https://github.com/rails/rails.git"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
6
 
13
7
  platforms :ruby do
14
8
  gem "sqlite3", "~> 1.4"
15
9
  end
16
10
 
17
11
  platforms :jruby do
18
- gem "activerecord-jdbc-adapter", "~> 52.0"
19
- gem "activerecord-jdbcpostgresql-adapter", "~> 52.0"
20
- gem "activerecord-jdbcmysql-adapter", "~> 52.0"
12
+ gem "activerecord-jdbc-adapter", "~> 61.0"
13
+ gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
14
+ gem "activerecord-jdbcmysql-adapter", "~> 61.0"
21
15
  end
22
16
 
23
17
  gemspec path: "../"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Style/ClassAndModuleChildren
4
+
5
+ # NOTE: This patch is meant to remove any schema_prefix appart from the ones for
6
+ # excluded models. The schema_prefix would be resolved by apartment's setting
7
+ # of search path
8
+ module Apartment::PostgreSqlAdapterPatch
9
+ def default_sequence_name(table, _column)
10
+ res = super
11
+ schema_prefix = "#{Apartment::Tenant.current}."
12
+ default_tenant_prefix = "#{Apartment::Tenant.default_tenant}."
13
+
14
+ # NOTE: Excluded models should always access the sequence from the default
15
+ # tenant schema
16
+ if excluded_model?(table)
17
+ res.sub!(schema_prefix, default_tenant_prefix) if schema_prefix != default_tenant_prefix
18
+ return res
19
+ end
20
+
21
+ res.delete_prefix!(schema_prefix) if res&.starts_with?(schema_prefix)
22
+
23
+ res
24
+ end
25
+
26
+ private
27
+
28
+ def excluded_model?(table)
29
+ Apartment.excluded_models.any? { |m| m.constantize.table_name == table }
30
+ end
31
+ end
32
+
33
+ require 'active_record/connection_adapters/postgresql_adapter'
34
+
35
+ # NOTE: inject this into postgresql adapters
36
+ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
37
+ include Apartment::PostgreSqlAdapterPatch
38
+ end
39
+ # rubocop:enable Style/ClassAndModuleChildren
@@ -38,11 +38,9 @@ module Apartment
38
38
  #
39
39
  def connect_to_new(tenant = nil)
40
40
  return reset if tenant.nil?
41
+ raise ActiveRecord::StatementInvalid, "Could not find schema #{tenant}" unless schema_exists?(tenant)
41
42
 
42
- tenant = tenant.to_s
43
- raise ActiveRecord::StatementInvalid, "Could not find schema #{tenant}" unless tenant_exists?(tenant)
44
-
45
- @current = tenant
43
+ @current = tenant.is_a?(Array) ? tenant.map(&:to_s) : tenant.to_s
46
44
  Apartment.connection.schema_search_path = full_search_path
47
45
  rescue ActiveRecord::StatementInvalid, ActiveRecord::JDBCError
48
46
  raise TenantNotFound, "One of the following schema(s) is invalid: #{full_search_path}"