ros-apartment 2.7.1 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +78 -0
  3. data/.github/workflows/changelog.yml +63 -0
  4. data/.rubocop.yml +78 -4
  5. data/.rubocop_todo.yml +50 -13
  6. data/CHANGELOG.md +963 -0
  7. data/Gemfile +2 -2
  8. data/Guardfile +0 -15
  9. data/HISTORY.md +93 -92
  10. data/README.md +27 -0
  11. data/Rakefile +5 -2
  12. data/gemfiles/rails_5_0.gemfile +1 -1
  13. data/gemfiles/rails_5_1.gemfile +1 -1
  14. data/gemfiles/rails_5_2.gemfile +1 -1
  15. data/gemfiles/rails_6_0.gemfile +1 -1
  16. data/gemfiles/rails_master.gemfile +1 -1
  17. data/lib/apartment.rb +5 -3
  18. data/lib/apartment/active_record/connection_handling.rb +3 -0
  19. data/lib/apartment/active_record/internal_metadata.rb +0 -2
  20. data/lib/apartment/active_record/schema_migration.rb +0 -2
  21. data/lib/apartment/adapters/abstract_adapter.rb +5 -3
  22. data/lib/apartment/adapters/abstract_jdbc_adapter.rb +2 -1
  23. data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +2 -1
  24. data/lib/apartment/adapters/mysql2_adapter.rb +3 -0
  25. data/lib/apartment/adapters/postgresql_adapter.rb +30 -7
  26. data/lib/apartment/console.rb +5 -9
  27. data/lib/apartment/custom_console.rb +2 -2
  28. data/lib/apartment/log_subscriber.rb +33 -0
  29. data/lib/apartment/railtie.rb +26 -21
  30. data/lib/apartment/tasks/task_helper.rb +7 -2
  31. data/lib/apartment/tenant.rb +7 -20
  32. data/lib/apartment/version.rb +1 -1
  33. data/lib/generators/apartment/install/templates/apartment.rb +2 -1
  34. data/lib/tasks/apartment.rake +4 -7
  35. data/ros-apartment.gemspec +2 -2
  36. metadata +12 -10
  37. data/.travis.yml +0 -49
  38. data/lib/apartment/active_record/log_subscriber.rb +0 -41
@@ -19,7 +19,6 @@ module Apartment
19
19
  def self.warn_if_tenants_empty
20
20
  return unless tenants.empty? && ENV['IGNORE_EMPTY_TENANTS'] != 'true'
21
21
 
22
- # rubocop:disable Rails/Output
23
22
  puts <<-WARNING
24
23
  [WARNING] - The list of tenants to migrate appears to be empty. This could mean a few things:
25
24
 
@@ -29,7 +28,13 @@ module Apartment
29
28
 
30
29
  Note that your tenants currently haven't been migrated. You'll need to run `db:migrate` to rectify this.
31
30
  WARNING
32
- # rubocop:enable Rails/Output
31
+ end
32
+
33
+ def self.create_tenant(tenant_name)
34
+ puts("Creating #{tenant_name} tenant")
35
+ Apartment::Tenant.create(tenant_name)
36
+ rescue Apartment::TenantExists => e
37
+ puts "Tried to create already existing tenant: #{e}"
33
38
  end
34
39
  end
35
40
  end
@@ -10,25 +10,10 @@ module Apartment
10
10
  extend Forwardable
11
11
 
12
12
  def_delegators :adapter, :create, :drop, :switch, :switch!, :current, :each,
13
- :reset, :init, :set_callback, :seed, :current_tenant,
14
- :default_tenant, :environmentify
13
+ :reset, :init, :set_callback, :seed, :default_tenant, :environmentify
15
14
 
16
15
  attr_writer :config
17
16
 
18
- def init_once
19
- return if @already_initialized
20
-
21
- # To avoid infinite loops in work init is doing,
22
- # we need to set @already_initialized to true
23
- # before init is called
24
- @already_initialized = true
25
- init
26
- end
27
-
28
- def reinitialize
29
- @already_initialized = false
30
- end
31
-
32
17
  # Fetch the proper multi-tenant adapter based on Rails config
33
18
  #
34
19
  # @return {subclass of Apartment::AbstractAdapter}
@@ -38,9 +23,10 @@ module Apartment
38
23
  adapter_method = "#{config[:adapter]}_adapter"
39
24
 
40
25
  if defined?(JRUBY_VERSION)
41
- if config[:adapter] =~ /mysql/
26
+ case config[:adapter]
27
+ when /mysql/
42
28
  adapter_method = 'jdbc_mysql_adapter'
43
- elsif config[:adapter] =~ /postgresql/
29
+ when /postgresql/
44
30
  adapter_method = 'jdbc_postgresql_adapter'
45
31
  end
46
32
  end
@@ -51,7 +37,9 @@ module Apartment
51
37
  raise "The adapter `#{adapter_method}` is not yet supported"
52
38
  end
53
39
 
54
- raise AdapterNotFound, "database configuration specifies nonexistent #{config[:adapter]} adapter" unless respond_to?(adapter_method)
40
+ unless respond_to?(adapter_method)
41
+ raise AdapterNotFound, "database configuration specifies nonexistent #{config[:adapter]} adapter"
42
+ end
55
43
 
56
44
  send(adapter_method, config)
57
45
  end
@@ -61,7 +49,6 @@ module Apartment
61
49
  #
62
50
  def reload!(config = nil)
63
51
  Thread.current[:apartment_adapter] = nil
64
- reinitialize
65
52
  @config = config
66
53
  end
67
54
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apartment
4
- VERSION = '2.7.1'
4
+ VERSION = '2.8.1'
5
5
  end
@@ -23,7 +23,8 @@ Apartment.configure do |config|
23
23
  # You can make this dynamic by providing a Proc object to be called on migrations.
24
24
  # This object should yield either:
25
25
  # - an array of strings representing each Tenant name.
26
- # - a hash which keys are tenant names, and values custom db config (must contain all key/values required in database.yml)
26
+ # - a hash which keys are tenant names, and values custom db config
27
+ # (must contain all key/values required in database.yml)
27
28
  #
28
29
  # config.tenant_names = lambda{ Customer.pluck(:tenant_name) }
29
30
  # config.tenant_names = ['tenant1', 'tenant2']
@@ -10,12 +10,7 @@ apartment_namespace = namespace :apartment do
10
10
  Apartment::TaskHelper.warn_if_tenants_empty
11
11
 
12
12
  Apartment::TaskHelper.tenants.each do |tenant|
13
- begin
14
- puts("Creating #{tenant} tenant")
15
- Apartment::Tenant.create(tenant)
16
- rescue Apartment::TenantExists => e
17
- puts e.message
18
- end
13
+ Apartment::TaskHelper.create_tenant(tenant)
19
14
  end
20
15
  end
21
16
 
@@ -36,6 +31,7 @@ apartment_namespace = namespace :apartment do
36
31
  Apartment::TaskHelper.warn_if_tenants_empty
37
32
  Apartment::TaskHelper.each_tenant do |tenant|
38
33
  begin
34
+ Apartment::TaskHelper.create_tenant(tenant)
39
35
  puts("Migrating #{tenant} tenant")
40
36
  Apartment::Migrator.migrate tenant
41
37
  rescue Apartment::TenantNotFound => e
@@ -45,11 +41,12 @@ apartment_namespace = namespace :apartment do
45
41
  end
46
42
 
47
43
  desc 'Seed all tenants'
48
- task seed: :create do
44
+ task :seed do
49
45
  Apartment::TaskHelper.warn_if_tenants_empty
50
46
 
51
47
  Apartment::TaskHelper.each_tenant do |tenant|
52
48
  begin
49
+ Apartment::TaskHelper.create_tenant(tenant)
53
50
  puts("Seeding #{tenant} tenant")
54
51
  Apartment::Tenant.switch(tenant) do
55
52
  Apartment::Tenant.seed
@@ -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)/})
20
+ f.match(%r{^(test|spec|features|documentation)/})
21
21
  end
22
22
  end
23
23
  s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.homepage = 'https://github.com/rails-on-services/apartment'
28
28
  s.licenses = ['MIT']
29
29
 
30
- s.add_dependency 'activerecord', '>= 5.0.0', '< 6.1'
30
+ s.add_dependency 'activerecord', '>= 5.0.0', '< 6.2'
31
31
  s.add_dependency 'parallel', '< 2.0'
32
32
  s.add_dependency 'public_suffix', '>= 2.0.5', '< 5.0'
33
33
  s.add_dependency 'rack', '>= 1.3.6', '< 3.0'
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ros-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
8
8
  - Brad Robertson
9
9
  - Rui Baltazar
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-06-27 00:00:00.000000000 Z
13
+ date: 2020-12-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 5.0.0
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '6.1'
24
+ version: '6.2'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: 5.0.0
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '6.1'
34
+ version: '6.2'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: parallel
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -228,15 +228,17 @@ executables: []
228
228
  extensions: []
229
229
  extra_rdoc_files: []
230
230
  files:
231
+ - ".circleci/config.yml"
231
232
  - ".github/ISSUE_TEMPLATE.md"
233
+ - ".github/workflows/changelog.yml"
232
234
  - ".gitignore"
233
235
  - ".pryrc"
234
236
  - ".rspec"
235
237
  - ".rubocop.yml"
236
238
  - ".rubocop_todo.yml"
237
239
  - ".story_branch.yml"
238
- - ".travis.yml"
239
240
  - Appraisals
241
+ - CHANGELOG.md
240
242
  - Gemfile
241
243
  - Guardfile
242
244
  - HISTORY.md
@@ -253,7 +255,6 @@ files:
253
255
  - lib/apartment.rb
254
256
  - lib/apartment/active_record/connection_handling.rb
255
257
  - lib/apartment/active_record/internal_metadata.rb
256
- - lib/apartment/active_record/log_subscriber.rb
257
258
  - lib/apartment/active_record/schema_migration.rb
258
259
  - lib/apartment/adapters/abstract_adapter.rb
259
260
  - lib/apartment/adapters/abstract_jdbc_adapter.rb
@@ -272,6 +273,7 @@ files:
272
273
  - lib/apartment/elevators/host.rb
273
274
  - lib/apartment/elevators/host_hash.rb
274
275
  - lib/apartment/elevators/subdomain.rb
276
+ - lib/apartment/log_subscriber.rb
275
277
  - lib/apartment/migrator.rb
276
278
  - lib/apartment/model.rb
277
279
  - lib/apartment/railtie.rb
@@ -289,7 +291,7 @@ homepage: https://github.com/rails-on-services/apartment
289
291
  licenses:
290
292
  - MIT
291
293
  metadata: {}
292
- post_install_message:
294
+ post_install_message:
293
295
  rdoc_options: []
294
296
  require_paths:
295
297
  - lib
@@ -304,8 +306,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
306
  - !ruby/object:Gem::Version
305
307
  version: '0'
306
308
  requirements: []
307
- rubygems_version: 3.0.3
308
- signing_key:
309
+ rubygems_version: 3.1.4
310
+ signing_key:
309
311
  specification_version: 4
310
312
  summary: A Ruby gem for managing database multitenancy. Apartment Gem drop in replacement
311
313
  test_files: []
@@ -1,49 +0,0 @@
1
- os: linux
2
-
3
- language: ruby
4
- services:
5
- - docker
6
- rvm:
7
- - jruby-9.2.11.0
8
- - 2.4.10
9
- - 2.5.8
10
- - 2.6.6
11
- - 2.7.1
12
- - jruby-head
13
- - ruby-head
14
-
15
- branches:
16
- only:
17
- - master
18
- - development
19
-
20
- gemfile:
21
- - gemfiles/rails_5_0.gemfile
22
- - gemfiles/rails_5_1.gemfile
23
- - gemfiles/rails_5_2.gemfile
24
- - gemfiles/rails_6_0.gemfile
25
- - gemfiles/rails_master.gemfile
26
-
27
- bundler_args: --without local
28
- before_install:
29
- - sudo /etc/init.d/mysql stop
30
- - sudo /etc/init.d/postgresql stop
31
- - docker-compose up -d
32
-
33
- env:
34
- RUBY_GC_MALLOC_LIMIT: 90000000
35
- RUBY_GC_HEAP_FREE_SLOTS: 200000
36
- jobs:
37
- include:
38
- - name: Rubocop Lint
39
- script: gem install perx-rubocop && rubocop
40
-
41
- allow_failures:
42
- - rvm: ruby-head
43
- - rvm: jruby-head
44
- - gemfile: gemfiles/rails_master.gemfile
45
- exclude:
46
- - rvm: 2.4.10
47
- gemfile: gemfiles/rails_6_0.gemfile
48
- fast_finish: true
49
- cache: bundler
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecord
4
- class LogSubscriber
5
- def apartment_log
6
- return unless Apartment.active_record_log
7
-
8
- database = color("[#{Apartment.connection.current_database}] ", ActiveSupport::LogSubscriber::MAGENTA, true)
9
- schema = nil
10
- schema = color("[#{Apartment.connection.schema_search_path.tr('"', '')}] ", ActiveSupport::LogSubscriber::YELLOW, true) unless Apartment.connection.schema_search_path.nil?
11
- "#{database}#{schema}"
12
- end
13
-
14
- def payload_binds(binds, type_casted_binds)
15
- return unless (binds || []).empty?
16
-
17
- casted_params = type_casted_binds(type_casted_binds)
18
- binds = ' ' + binds.zip(casted_params).map { |attr, value| render_bind(attr, value) }.inspect
19
- binds
20
- end
21
-
22
- def sql(event)
23
- self.class.runtime += event.duration
24
- return unless logger.debug?
25
-
26
- payload = event.payload
27
-
28
- return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])
29
-
30
- name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
31
- name = "CACHE #{name}" if payload[:cached]
32
- sql = payload[:sql]
33
- binds = payload_binds(payload[:binds], payload[:type_casted_binds])
34
-
35
- name = colorize_payload_name(name, payload[:name])
36
- sql = color(sql, sql_color(sql), true) if colorize_logging
37
-
38
- debug " #{apartment_log}#{name} #{sql}#{binds}"
39
- end
40
- end
41
- end