ros-apartment 2.11.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,26 +8,38 @@ module Apartment
8
8
  # NOTE: for some reason, if the method definition is not here, then the custom debug method is not called
9
9
  # rubocop:disable Lint/UselessMethodDefinition
10
10
  def sql(event)
11
- super(event)
11
+ super
12
12
  end
13
13
  # rubocop:enable Lint/UselessMethodDefinition
14
14
 
15
15
  private
16
16
 
17
- def debug(progname = nil, &block)
17
+ def debug(progname = nil, &)
18
18
  progname = " #{apartment_log}#{progname}" unless progname.nil?
19
19
 
20
- super(progname, &block)
20
+ super
21
21
  end
22
22
 
23
23
  def apartment_log
24
- database = color("[#{Apartment.connection.raw_connection.db}] ", ActiveSupport::LogSubscriber::MAGENTA, true)
25
- schema = nil
26
- unless Apartment.connection.schema_search_path.nil?
27
- schema = color("[#{Apartment.connection.schema_search_path.tr('"', '')}] ",
28
- ActiveSupport::LogSubscriber::YELLOW, true)
29
- end
24
+ database = color("[#{database_name}] ", ActiveSupport::LogSubscriber::MAGENTA, bold: true)
25
+ schema = current_search_path
26
+ schema = color("[#{schema.tr('"', '')}] ", ActiveSupport::LogSubscriber::YELLOW, bold: true) unless schema.nil?
30
27
  "#{database}#{schema}"
31
28
  end
29
+
30
+ def current_search_path
31
+ if Apartment.connection.respond_to?(:schema_search_path)
32
+ Apartment.connection.schema_search_path
33
+ else
34
+ Apartment::Tenant.current # all others
35
+ end
36
+ end
37
+
38
+ def database_name
39
+ db_name = Apartment.connection.raw_connection.try(:db) # PostgreSQL, PostGIS
40
+ db_name ||= Apartment.connection.raw_connection.try(:query_options)&.dig(:database) # Mysql
41
+ db_name ||= Apartment.connection.current_database # Failover
42
+ db_name
43
+ end
32
44
  end
33
45
  end
@@ -13,40 +13,22 @@ module Apartment
13
13
 
14
14
  migration_scope_block = ->(migration) { ENV['SCOPE'].blank? || (ENV['SCOPE'] == migration.scope) }
15
15
 
16
- if activerecord_below_5_2?
17
- ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, version, &migration_scope_block)
18
- else
19
- ActiveRecord::Base.connection.migration_context.migrate(version, &migration_scope_block)
20
- end
16
+ ActiveRecord::Base.connection.migration_context.migrate(version, &migration_scope_block)
21
17
  end
22
18
  end
23
19
 
24
20
  # Migrate up/down to a specific version
25
21
  def run(direction, database, version)
26
22
  Tenant.switch(database) do
27
- if activerecord_below_5_2?
28
- ActiveRecord::Migrator.run(direction, ActiveRecord::Migrator.migrations_paths, version)
29
- else
30
- ActiveRecord::Base.connection.migration_context.run(direction, version)
31
- end
23
+ ActiveRecord::Base.connection.migration_context.run(direction, version)
32
24
  end
33
25
  end
34
26
 
35
27
  # rollback latest migration `step` number of times
36
28
  def rollback(database, step = 1)
37
29
  Tenant.switch(database) do
38
- if activerecord_below_5_2?
39
- ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
40
- else
41
- ActiveRecord::Base.connection.migration_context.rollback(step)
42
- end
30
+ ActiveRecord::Base.connection.migration_context.rollback(step)
43
31
  end
44
32
  end
45
-
46
- private
47
-
48
- def activerecord_below_5_2?
49
- ActiveRecord.version.release < Gem::Version.new('5.2.0')
50
- end
51
33
  end
52
34
  end
@@ -47,7 +47,12 @@ module Apartment
47
47
  config.after_initialize do
48
48
  # NOTE: Load the custom log subscriber if enabled
49
49
  if Apartment.active_record_log
50
- ActiveSupport::Notifications.unsubscribe 'sql.active_record'
50
+ ActiveSupport::Notifications.notifier.listeners_for('sql.active_record').each do |listener|
51
+ next unless listener.instance_variable_get('@delegate').is_a?(ActiveRecord::LogSubscriber)
52
+
53
+ ActiveSupport::Notifications.unsubscribe listener
54
+ end
55
+
51
56
  Apartment::LogSubscriber.attach_to :active_record
52
57
  end
53
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apartment
4
- VERSION = '2.11.0'
4
+ VERSION = '3.0.1'
5
5
  end
data/lib/apartment.rb CHANGED
@@ -7,15 +7,9 @@ require 'active_record'
7
7
  require 'apartment/tenant'
8
8
 
9
9
  require_relative 'apartment/log_subscriber'
10
-
11
- if ActiveRecord.version.release >= Gem::Version.new('6.0')
12
- require_relative 'apartment/active_record/connection_handling'
13
- end
14
-
15
- if ActiveRecord.version.release >= Gem::Version.new('6.1')
16
- require_relative 'apartment/active_record/schema_migration'
17
- require_relative 'apartment/active_record/internal_metadata'
18
- end
10
+ require_relative 'apartment/active_record/connection_handling'
11
+ require_relative 'apartment/active_record/schema_migration'
12
+ require_relative 'apartment/active_record/internal_metadata'
19
13
 
20
14
  # Apartment main definitions
21
15
  module Apartment
@@ -33,14 +27,10 @@ module Apartment
33
27
  attr_accessor(*ACCESSOR_METHODS)
34
28
  attr_writer(*WRITER_METHODS)
35
29
 
36
- if ActiveRecord.version.release >= Gem::Version.new('6.1')
37
- def_delegators :connection_class, :connection, :connection_db_config, :establish_connection
30
+ def_delegators :connection_class, :connection, :connection_db_config, :establish_connection
38
31
 
39
- def connection_config
40
- connection_db_config.configuration_hash
41
- end
42
- else
43
- def_delegators :connection_class, :connection, :connection_config, :establish_connection
32
+ def connection_config
33
+ connection_db_config.configuration_hash
44
34
  end
45
35
 
46
36
  # configure apartment with available options
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.files = Dir.chdir(File.expand_path(__dir__)) do
18
18
  `git ls-files -z`.split("\x0").reject do |f|
19
19
  # NOTE: ignore all test related
20
- f.match(%r{^(test|spec|features|documentation)/})
20
+ f.match(%r{^(test|spec|features|documentation|gemfiles|.github)/})
21
21
  end
22
22
  end
23
23
  s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
@@ -26,11 +26,14 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.homepage = 'https://github.com/rails-on-services/apartment'
28
28
  s.licenses = ['MIT']
29
+ s.metadata = {
30
+ 'github_repo' => 'ssh://github.com/rails-on-services/apartment'
31
+ }
29
32
 
30
- s.add_dependency 'activerecord', '>= 5.0.0', '< 7.1'
33
+ s.add_dependency 'activerecord', '>= 6.1.0', '< 7.2'
31
34
  s.add_dependency 'parallel', '< 2.0'
32
- s.add_dependency 'public_suffix', '>= 2.0.5', '< 5.0'
33
- s.add_dependency 'rack', '>= 1.3.6', '< 3.0'
35
+ s.add_dependency 'public_suffix', '>= 2.0.5', '< 6.0'
36
+ s.add_dependency 'rack', '>= 1.3.6', '< 4.0'
34
37
 
35
38
  s.add_development_dependency 'appraisal', '~> 2.2'
36
39
  s.add_development_dependency 'bundler', '>= 1.3', '< 3.0'
@@ -39,11 +42,11 @@ Gem::Specification.new do |s|
39
42
  s.add_development_dependency 'rake', '~> 13.0'
40
43
  s.add_development_dependency 'rspec', '~> 3.4'
41
44
  s.add_development_dependency 'rspec_junit_formatter'
42
- s.add_development_dependency 'rspec-rails', '~> 3.4'
43
- s.add_development_dependency 'rubocop', '~> 0.93'
44
- s.add_development_dependency 'rubocop-performance', '~> 1.10'
45
- s.add_development_dependency 'rubocop-rails', '~> 2.1'
46
- s.add_development_dependency 'rubocop-rspec', '~> 1.44'
45
+ s.add_development_dependency 'rspec-rails', '~> 6.1'
46
+ s.add_development_dependency 'rubocop', '~> 1.63'
47
+ s.add_development_dependency 'rubocop-performance', '~> 1.21'
48
+ s.add_development_dependency 'rubocop-rails', '~> 2.24'
49
+ s.add_development_dependency 'rubocop-rspec', '~> 2.29'
47
50
 
48
51
  if defined?(JRUBY_VERSION)
49
52
  s.add_development_dependency 'activerecord-jdbc-adapter'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ros-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-02-07 00:00:00.000000000 Z
13
+ date: 2024-05-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,20 +18,20 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 5.0.0
21
+ version: 6.1.0
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '7.1'
24
+ version: '7.2'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 5.0.0
31
+ version: 6.1.0
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '7.1'
34
+ version: '7.2'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: parallel
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 2.0.5
56
56
  - - "<"
57
57
  - !ruby/object:Gem::Version
58
- version: '5.0'
58
+ version: '6.0'
59
59
  type: :runtime
60
60
  prerelease: false
61
61
  version_requirements: !ruby/object:Gem::Requirement
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 2.0.5
66
66
  - - "<"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.0'
68
+ version: '6.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: 1.3.6
76
76
  - - "<"
77
77
  - !ruby/object:Gem::Version
78
- version: '3.0'
78
+ version: '4.0'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: 1.3.6
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.0'
88
+ version: '4.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: appraisal
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -196,70 +196,70 @@ dependencies:
196
196
  requirements:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
- version: '3.4'
199
+ version: '6.1'
200
200
  type: :development
201
201
  prerelease: false
202
202
  version_requirements: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - "~>"
205
205
  - !ruby/object:Gem::Version
206
- version: '3.4'
206
+ version: '6.1'
207
207
  - !ruby/object:Gem::Dependency
208
208
  name: rubocop
209
209
  requirement: !ruby/object:Gem::Requirement
210
210
  requirements:
211
211
  - - "~>"
212
212
  - !ruby/object:Gem::Version
213
- version: '0.93'
213
+ version: '1.63'
214
214
  type: :development
215
215
  prerelease: false
216
216
  version_requirements: !ruby/object:Gem::Requirement
217
217
  requirements:
218
218
  - - "~>"
219
219
  - !ruby/object:Gem::Version
220
- version: '0.93'
220
+ version: '1.63'
221
221
  - !ruby/object:Gem::Dependency
222
222
  name: rubocop-performance
223
223
  requirement: !ruby/object:Gem::Requirement
224
224
  requirements:
225
225
  - - "~>"
226
226
  - !ruby/object:Gem::Version
227
- version: '1.10'
227
+ version: '1.21'
228
228
  type: :development
229
229
  prerelease: false
230
230
  version_requirements: !ruby/object:Gem::Requirement
231
231
  requirements:
232
232
  - - "~>"
233
233
  - !ruby/object:Gem::Version
234
- version: '1.10'
234
+ version: '1.21'
235
235
  - !ruby/object:Gem::Dependency
236
236
  name: rubocop-rails
237
237
  requirement: !ruby/object:Gem::Requirement
238
238
  requirements:
239
239
  - - "~>"
240
240
  - !ruby/object:Gem::Version
241
- version: '2.1'
241
+ version: '2.24'
242
242
  type: :development
243
243
  prerelease: false
244
244
  version_requirements: !ruby/object:Gem::Requirement
245
245
  requirements:
246
246
  - - "~>"
247
247
  - !ruby/object:Gem::Version
248
- version: '2.1'
248
+ version: '2.24'
249
249
  - !ruby/object:Gem::Dependency
250
250
  name: rubocop-rspec
251
251
  requirement: !ruby/object:Gem::Requirement
252
252
  requirements:
253
253
  - - "~>"
254
254
  - !ruby/object:Gem::Version
255
- version: '1.44'
255
+ version: '2.29'
256
256
  type: :development
257
257
  prerelease: false
258
258
  version_requirements: !ruby/object:Gem::Requirement
259
259
  requirements:
260
260
  - - "~>"
261
261
  - !ruby/object:Gem::Version
262
- version: '1.44'
262
+ version: '2.29'
263
263
  - !ruby/object:Gem::Dependency
264
264
  name: mysql2
265
265
  requirement: !ruby/object:Gem::Requirement
@@ -312,31 +312,18 @@ executables: []
312
312
  extensions: []
313
313
  extra_rdoc_files: []
314
314
  files:
315
- - ".circleci/config.yml"
316
- - ".github/ISSUE_TEMPLATE.md"
317
- - ".github/workflows/changelog.yml"
318
- - ".github/workflows/reviewdog.yml"
319
315
  - ".gitignore"
320
316
  - ".pryrc"
321
317
  - ".rspec"
322
318
  - ".rubocop.yml"
323
319
  - ".rubocop_todo.yml"
324
320
  - ".ruby-version"
325
- - ".story_branch.yml"
326
321
  - Appraisals
327
322
  - CHANGELOG.md
328
323
  - Gemfile
329
324
  - Guardfile
330
- - HISTORY.md
331
325
  - README.md
332
326
  - Rakefile
333
- - TODO.md
334
- - docker-compose.yml
335
- - gemfiles/rails_5_2.gemfile
336
- - gemfiles/rails_6_0.gemfile
337
- - gemfiles/rails_6_1.gemfile
338
- - gemfiles/rails_7_0.gemfile
339
- - gemfiles/rails_master.gemfile
340
327
  - lib/apartment.rb
341
328
  - lib/apartment/active_record/connection_handling.rb
342
329
  - lib/apartment/active_record/internal_metadata.rb
@@ -375,7 +362,8 @@ files:
375
362
  homepage: https://github.com/rails-on-services/apartment
376
363
  licenses:
377
364
  - MIT
378
- metadata: {}
365
+ metadata:
366
+ github_repo: ssh://github.com/rails-on-services/apartment
379
367
  post_install_message:
380
368
  rdoc_options: []
381
369
  require_paths:
@@ -391,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
391
379
  - !ruby/object:Gem::Version
392
380
  version: '0'
393
381
  requirements: []
394
- rubygems_version: 3.1.6
382
+ rubygems_version: 3.3.26
395
383
  signing_key:
396
384
  specification_version: 4
397
385
  summary: A Ruby gem for managing database multitenancy. Apartment Gem drop in replacement
data/.circleci/config.yml DELETED
@@ -1,78 +0,0 @@
1
- version: 2.1
2
-
3
- jobs:
4
- build:
5
- docker:
6
- - image: circleci/<< parameters.ruby_version >>
7
- - image: circleci/postgres:9.6.2-alpine
8
- - image: circleci/mysql:5.7
9
- environment:
10
- MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
11
- parameters:
12
- ruby_version:
13
- type: string
14
- gemfile:
15
- type: string
16
- environment:
17
- BUNDLE_GEMFILE: << parameters.gemfile >>
18
- steps:
19
- - checkout
20
- # Restore Cached Dependencies
21
- # - restore_cache:
22
- # keys:
23
- # - gem-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "<< parameters.gemfile >>.lock" }}
24
- # - gem-cache-v1-{{ arch }}-{{ .Branch }}
25
- # - gem-cache-v1
26
-
27
- - run: bundle install --path vendor/bundle
28
-
29
- # - save_cache:
30
- # key: gem-cache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "<< parameters.gemfile >>.lock" }}
31
- # paths:
32
- # - vendor/bundle
33
-
34
- - run:
35
- name: Install postgres client
36
- command: sudo apt install -y postgresql-client
37
-
38
- - run:
39
- name: Install mysql client
40
- command: sudo apt install -y default-mysql-client
41
-
42
- - run:
43
- name: Configure config database.yml
44
- command: bundle exec rake db:copy_credentials
45
-
46
- - run:
47
- name: wait for postgresql
48
- command: dockerize -wait tcp://localhost:5432 -timeout 1m
49
-
50
- - run:
51
- name: wait for mysql
52
- command: dockerize -wait tcp://localhost:3306 -timeout 1m
53
-
54
- - run:
55
- name: Database Setup
56
- command: |
57
- bundle exec rake db:test:prepare
58
-
59
- - run:
60
- name: Run tests
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
-
66
- workflows:
67
- tests:
68
- jobs:
69
- - build:
70
- matrix:
71
- parameters:
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"
@@ -1,21 +0,0 @@
1
- ## Steps to reproduce
2
-
3
- ## Expected behavior
4
-
5
- ## Actual behavior
6
-
7
- ## System configuration
8
-
9
- <!-- Please let us know as far as you can. -->
10
-
11
- * Database: (Tell us what database and its version you use.)
12
-
13
- * Apartment version:
14
-
15
- * Apartment config (in `config/initializers/apartment.rb` or so):
16
-
17
- * `use_schemas`: (`true` or `false`)
18
-
19
- * Rails (or ActiveRecord) version:
20
-
21
- * Ruby version:
@@ -1,63 +0,0 @@
1
- name: Changelog
2
-
3
- on:
4
- pull_request:
5
- types: [closed]
6
-
7
- release:
8
- types: [published]
9
-
10
- issues:
11
- types: [closed, edited]
12
-
13
- jobs:
14
- generate_changelog:
15
- runs-on: ubuntu-latest
16
- name: Generate changelog for master branch
17
- steps:
18
- - uses: actions/checkout@v2
19
- with:
20
- fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
21
-
22
- - name: Generate changelog
23
- uses: charmixer/auto-changelog-action@v1
24
- with:
25
- token: ${{ secrets.GITHUB_TOKEN }}
26
-
27
- - name: Commit files
28
- env:
29
- ACTION_EMAIL: action@github.com
30
- ACTION_USERNAME: GitHub Action
31
- run: |
32
- git config --local user.email "$ACTION_EMAIL"
33
- git config --local user.name "$ACTION_USERNAME"
34
- git add CHANGELOG.md && git commit -m 'Updated CHANGELOG.md' && echo ::set-env name=push::1 || echo "No changes to CHANGELOG.md"
35
-
36
- - name: Push changes
37
- if: env.push == 1
38
- env:
39
- # CI_USER: ${{ secrets.YOUR_GITHUB_USER }}
40
- CI_TOKEN: ${{ secrets.CHANGELOG_GITHUB_TOKEN }}
41
- run: |
42
- git push "https://$GITHUB_ACTOR:$CI_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:master
43
-
44
- # - name: Push changelog to master
45
- # if: env.push == 1
46
- # uses: ad-m/github-push-action@master
47
- # with:
48
- # github_token: ${{ secrets.CHANGELOG_GITHUB_TOKEN }}
49
- # branch: master
50
-
51
- # - name: Cherry-pick changelog to development
52
- # if: env.push == 1
53
- # env:
54
- # ACTION_EMAIL: action@github.com
55
- # ACTION_USERNAME: GitHub Action
56
- # run: |
57
- # git config --local user.email "$ACTION_EMAIL"
58
- # git config --local user.name "$ACTION_USERNAME"
59
- # commit_hash=`git show HEAD | egrep commit\ .+$ | cut -d' ' -f2`
60
- # git checkout development
61
- # git pull
62
- # git cherry-pick $commit_hash
63
- # git push
@@ -1,22 +0,0 @@
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/.story_branch.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- tracker: github
3
- issue_placement: beginning
4
- project_id:
5
- - rails-on-services/apartment