ros-apartment 2.3.0.alpha2 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/.rubocop-linter.yml +22 -0
  3. data/.pryrc +5 -3
  4. data/.rubocop.yml +21 -0
  5. data/.rubocop_todo.yml +29 -0
  6. data/.story_branch.yml +4 -0
  7. data/.travis.yml +15 -36
  8. data/Appraisals +16 -29
  9. data/Gemfile +4 -1
  10. data/Guardfile +3 -1
  11. data/HISTORY.md +7 -0
  12. data/README.md +80 -39
  13. data/Rakefile +45 -23
  14. data/apartment.gemspec +33 -25
  15. data/gemfiles/rails_4_2.gemfile +12 -10
  16. data/gemfiles/rails_5_0.gemfile +2 -1
  17. data/gemfiles/rails_5_1.gemfile +2 -1
  18. data/gemfiles/rails_5_2.gemfile +2 -1
  19. data/gemfiles/rails_6_0.gemfile +6 -5
  20. data/gemfiles/rails_master.gemfile +2 -1
  21. data/lib/apartment.rb +36 -11
  22. data/lib/apartment/active_record/connection_handling.rb +17 -0
  23. data/lib/apartment/active_record/internal_metadata.rb +11 -0
  24. data/lib/apartment/active_record/schema_migration.rb +13 -0
  25. data/lib/apartment/adapters/abstract_adapter.rb +50 -45
  26. data/lib/apartment/adapters/abstract_jdbc_adapter.rb +4 -3
  27. data/lib/apartment/adapters/jdbc_mysql_adapter.rb +3 -3
  28. data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +20 -13
  29. data/lib/apartment/adapters/mysql2_adapter.rb +10 -9
  30. data/lib/apartment/adapters/postgis_adapter.rb +3 -2
  31. data/lib/apartment/adapters/postgresql_adapter.rb +55 -27
  32. data/lib/apartment/adapters/sqlite3_adapter.rb +18 -8
  33. data/lib/apartment/console.rb +35 -3
  34. data/lib/apartment/custom_console.rb +42 -0
  35. data/lib/apartment/deprecation.rb +2 -1
  36. data/lib/apartment/elevators/domain.rb +4 -3
  37. data/lib/apartment/elevators/first_subdomain.rb +3 -2
  38. data/lib/apartment/elevators/generic.rb +4 -3
  39. data/lib/apartment/elevators/host.rb +6 -1
  40. data/lib/apartment/elevators/host_hash.rb +6 -2
  41. data/lib/apartment/elevators/subdomain.rb +9 -5
  42. data/lib/apartment/migrator.rb +4 -3
  43. data/lib/apartment/model.rb +27 -0
  44. data/lib/apartment/railtie.rb +26 -15
  45. data/lib/apartment/reloader.rb +2 -1
  46. data/lib/apartment/tasks/enhancements.rb +4 -6
  47. data/lib/apartment/tenant.rb +19 -9
  48. data/lib/apartment/version.rb +3 -1
  49. data/lib/generators/apartment/install/install_generator.rb +4 -3
  50. data/lib/generators/apartment/install/templates/apartment.rb +3 -2
  51. data/lib/tasks/apartment.rake +24 -19
  52. metadata +79 -256
  53. data/spec/adapters/jdbc_mysql_adapter_spec.rb +0 -19
  54. data/spec/adapters/jdbc_postgresql_adapter_spec.rb +0 -41
  55. data/spec/adapters/mysql2_adapter_spec.rb +0 -59
  56. data/spec/adapters/postgresql_adapter_spec.rb +0 -61
  57. data/spec/adapters/sqlite3_adapter_spec.rb +0 -83
  58. data/spec/apartment_spec.rb +0 -11
  59. data/spec/config/database.yml.sample +0 -49
  60. data/spec/dummy/Rakefile +0 -7
  61. data/spec/dummy/app/controllers/application_controller.rb +0 -6
  62. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  63. data/spec/dummy/app/models/company.rb +0 -3
  64. data/spec/dummy/app/models/user.rb +0 -3
  65. data/spec/dummy/app/views/application/index.html.erb +0 -1
  66. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  67. data/spec/dummy/config.ru +0 -4
  68. data/spec/dummy/config/application.rb +0 -49
  69. data/spec/dummy/config/boot.rb +0 -11
  70. data/spec/dummy/config/database.yml.sample +0 -44
  71. data/spec/dummy/config/environment.rb +0 -5
  72. data/spec/dummy/config/environments/development.rb +0 -28
  73. data/spec/dummy/config/environments/production.rb +0 -51
  74. data/spec/dummy/config/environments/test.rb +0 -34
  75. data/spec/dummy/config/initializers/apartment.rb +0 -4
  76. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  77. data/spec/dummy/config/initializers/inflections.rb +0 -10
  78. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  79. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  80. data/spec/dummy/config/initializers/session_store.rb +0 -8
  81. data/spec/dummy/config/locales/en.yml +0 -5
  82. data/spec/dummy/config/routes.rb +0 -3
  83. data/spec/dummy/db/migrate/20110613152810_create_dummy_models.rb +0 -39
  84. data/spec/dummy/db/migrate/20111202022214_create_table_books.rb +0 -14
  85. data/spec/dummy/db/migrate/20180415260934_create_public_tokens.rb +0 -13
  86. data/spec/dummy/db/schema.rb +0 -55
  87. data/spec/dummy/db/seeds.rb +0 -5
  88. data/spec/dummy/db/seeds/import.rb +0 -5
  89. data/spec/dummy/public/404.html +0 -26
  90. data/spec/dummy/public/422.html +0 -26
  91. data/spec/dummy/public/500.html +0 -26
  92. data/spec/dummy/public/favicon.ico +0 -0
  93. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  94. data/spec/dummy/script/rails +0 -6
  95. data/spec/dummy_engine/.gitignore +0 -8
  96. data/spec/dummy_engine/Gemfile +0 -15
  97. data/spec/dummy_engine/Rakefile +0 -34
  98. data/spec/dummy_engine/bin/rails +0 -12
  99. data/spec/dummy_engine/config/initializers/apartment.rb +0 -51
  100. data/spec/dummy_engine/dummy_engine.gemspec +0 -24
  101. data/spec/dummy_engine/lib/dummy_engine.rb +0 -4
  102. data/spec/dummy_engine/lib/dummy_engine/engine.rb +0 -4
  103. data/spec/dummy_engine/lib/dummy_engine/version.rb +0 -3
  104. data/spec/dummy_engine/test/dummy/Rakefile +0 -6
  105. data/spec/dummy_engine/test/dummy/config.ru +0 -4
  106. data/spec/dummy_engine/test/dummy/config/application.rb +0 -22
  107. data/spec/dummy_engine/test/dummy/config/boot.rb +0 -5
  108. data/spec/dummy_engine/test/dummy/config/database.yml +0 -25
  109. data/spec/dummy_engine/test/dummy/config/environment.rb +0 -5
  110. data/spec/dummy_engine/test/dummy/config/environments/development.rb +0 -37
  111. data/spec/dummy_engine/test/dummy/config/environments/production.rb +0 -78
  112. data/spec/dummy_engine/test/dummy/config/environments/test.rb +0 -39
  113. data/spec/dummy_engine/test/dummy/config/initializers/assets.rb +0 -8
  114. data/spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  115. data/spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  116. data/spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  117. data/spec/dummy_engine/test/dummy/config/initializers/inflections.rb +0 -16
  118. data/spec/dummy_engine/test/dummy/config/initializers/mime_types.rb +0 -4
  119. data/spec/dummy_engine/test/dummy/config/initializers/session_store.rb +0 -3
  120. data/spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  121. data/spec/dummy_engine/test/dummy/config/locales/en.yml +0 -23
  122. data/spec/dummy_engine/test/dummy/config/routes.rb +0 -56
  123. data/spec/dummy_engine/test/dummy/config/secrets.yml +0 -22
  124. data/spec/examples/connection_adapter_examples.rb +0 -42
  125. data/spec/examples/generic_adapter_custom_configuration_example.rb +0 -95
  126. data/spec/examples/generic_adapter_examples.rb +0 -163
  127. data/spec/examples/schema_adapter_examples.rb +0 -234
  128. data/spec/integration/apartment_rake_integration_spec.rb +0 -107
  129. data/spec/integration/query_caching_spec.rb +0 -81
  130. data/spec/integration/use_within_an_engine_spec.rb +0 -28
  131. data/spec/schemas/v1.rb +0 -16
  132. data/spec/schemas/v2.rb +0 -43
  133. data/spec/schemas/v3.rb +0 -49
  134. data/spec/spec_helper.rb +0 -61
  135. data/spec/support/apartment_helpers.rb +0 -43
  136. data/spec/support/capybara_sessions.rb +0 -15
  137. data/spec/support/config.rb +0 -10
  138. data/spec/support/contexts.rb +0 -52
  139. data/spec/support/requirements.rb +0 -35
  140. data/spec/support/setup.rb +0 -46
  141. data/spec/tasks/apartment_rake_spec.rb +0 -129
  142. data/spec/tenant_spec.rb +0 -190
  143. data/spec/unit/config_spec.rb +0 -112
  144. data/spec/unit/elevators/domain_spec.rb +0 -32
  145. data/spec/unit/elevators/first_subdomain_spec.rb +0 -24
  146. data/spec/unit/elevators/generic_spec.rb +0 -54
  147. data/spec/unit/elevators/host_hash_spec.rb +0 -32
  148. data/spec/unit/elevators/host_spec.rb +0 -89
  149. data/spec/unit/elevators/subdomain_spec.rb +0 -76
  150. data/spec/unit/migrator_spec.rb +0 -77
  151. data/spec/unit/reloader_spec.rb +0 -24
data/Rakefile CHANGED
@@ -1,19 +1,25 @@
1
- require 'bundler' rescue 'You must `gem install bundler` and `bundle install` to run rake tasks'
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler'
5
+ rescue StandardError
6
+ 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
2
8
  Bundler.setup
3
9
  Bundler::GemHelper.install_tasks
4
10
 
5
11
  require 'appraisal'
6
12
 
7
- require "rspec"
8
- require "rspec/core/rake_task"
13
+ require 'rspec'
14
+ require 'rspec/core/rake_task'
9
15
 
10
- RSpec::Core::RakeTask.new(:spec => %w{ db:copy_credentials db:test:prepare }) do |spec|
11
- spec.pattern = "spec/**/*_spec.rb"
16
+ RSpec::Core::RakeTask.new(spec: %w[db:copy_credentials db:test:prepare]) do |spec|
17
+ spec.pattern = 'spec/**/*_spec.rb'
12
18
  # spec.rspec_opts = '--order rand:47078'
13
19
  end
14
20
 
15
21
  namespace :spec do
16
- [:tasks, :unit, :adapters, :integration].each do |type|
22
+ %i[tasks unit adapters integration].each do |type|
17
23
  RSpec::Core::RakeTask.new(type => :spec) do |spec|
18
24
  spec.pattern = "spec/#{type}/**/*_spec.rb"
19
25
  end
@@ -27,11 +33,11 @@ task :console do
27
33
  Pry.start
28
34
  end
29
35
 
30
- task :default => :spec
36
+ task default: :spec
31
37
 
32
38
  namespace :db do
33
39
  namespace :test do
34
- task :prepare => %w{postgres:drop_db postgres:build_db mysql:drop_db mysql:build_db}
40
+ task prepare: %w[postgres:drop_db postgres:build_db mysql:drop_db mysql:build_db]
35
41
  end
36
42
 
37
43
  desc "copy sample database credential files over if real files don't exist"
@@ -40,29 +46,33 @@ namespace :db do
40
46
  apartment_db_file = 'spec/config/database.yml'
41
47
  rails_db_file = 'spec/dummy/config/database.yml'
42
48
 
43
- FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, :verbose => true) unless File.exists?(apartment_db_file)
44
- FileUtils.copy(rails_db_file + '.sample', rails_db_file, :verbose => true) unless File.exists?(rails_db_file)
49
+ FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, verbose: true) unless File.exist?(apartment_db_file)
50
+ FileUtils.copy(rails_db_file + '.sample', rails_db_file, verbose: true) unless File.exist?(rails_db_file)
45
51
  end
46
52
  end
47
53
 
48
54
  namespace :postgres do
49
55
  require 'active_record'
50
- require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
56
+ require File.join(File.dirname(__FILE__), 'spec', 'support', 'config').to_s
51
57
 
52
58
  desc 'Build the PostgreSQL test databases'
53
59
  task :build_db do
54
60
  params = []
55
- params << "-E UTF8"
61
+ params << '-E UTF8'
56
62
  params << pg_config['database']
57
63
  params << "-U#{pg_config['username']}"
58
64
  params << "-h#{pg_config['host']}" if pg_config['host']
59
65
  params << "-p#{pg_config['port']}" if pg_config['port']
60
- %x{ createdb #{params.join(' ')} } rescue "test db already exists"
66
+ begin
67
+ `createdb #{params.join(' ')}`
68
+ rescue StandardError
69
+ 'test db already exists'
70
+ end
61
71
  ActiveRecord::Base.establish_connection pg_config
62
72
  migrate
63
73
  end
64
74
 
65
- desc "drop the PostgreSQL test database"
75
+ desc 'drop the PostgreSQL test database'
66
76
  task :drop_db do
67
77
  puts "dropping database #{pg_config['database']}"
68
78
  params = []
@@ -70,14 +80,13 @@ namespace :postgres do
70
80
  params << "-U#{pg_config['username']}"
71
81
  params << "-h#{pg_config['host']}" if pg_config['host']
72
82
  params << "-p#{pg_config['port']}" if pg_config['port']
73
- %x{ dropdb #{params.join(' ')} }
83
+ `dropdb #{params.join(' ')}`
74
84
  end
75
-
76
85
  end
77
86
 
78
87
  namespace :mysql do
79
88
  require 'active_record'
80
- require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
89
+ require File.join(File.dirname(__FILE__), 'spec', 'support', 'config').to_s
81
90
 
82
91
  desc 'Build the MySQL test databases'
83
92
  task :build_db do
@@ -85,24 +94,29 @@ namespace :mysql do
85
94
  params << "-h #{my_config['host']}" if my_config['host']
86
95
  params << "-u #{my_config['username']}" if my_config['username']
87
96
  params << "-p#{my_config['password']}" if my_config['password']
88
- %x{ mysqladmin #{params.join(' ')} create #{my_config['database']} } rescue "test db already exists"
97
+ params << "--port #{my_config['port']}" if my_config['port']
98
+ begin
99
+ `mysqladmin #{params.join(' ')} create #{my_config['database']}`
100
+ rescue StandardError
101
+ 'test db already exists'
102
+ end
89
103
  ActiveRecord::Base.establish_connection my_config
90
104
  migrate
91
105
  end
92
106
 
93
- desc "drop the MySQL test database"
107
+ desc 'drop the MySQL test database'
94
108
  task :drop_db do
95
109
  puts "dropping database #{my_config['database']}"
96
110
  params = []
97
111
  params << "-h #{my_config['host']}" if my_config['host']
98
112
  params << "-u #{my_config['username']}" if my_config['username']
99
113
  params << "-p#{my_config['password']}" if my_config['password']
100
- %x{ mysqladmin #{params.join(' ')} drop #{my_config['database']} --force}
114
+ params << "--port #{my_config['port']}" if my_config['port']
115
+ `mysqladmin #{params.join(' ')} drop #{my_config['database']} --force`
101
116
  end
102
-
103
117
  end
104
118
 
105
- # TODO clean this up
119
+ # TODO: clean this up
106
120
  def config
107
121
  Apartment::Test.config['connections']
108
122
  end
@@ -119,10 +133,18 @@ def activerecord_below_5_2?
119
133
  ActiveRecord.version.release < Gem::Version.new('5.2.0')
120
134
  end
121
135
 
136
+ def activerecord_below_6_0?
137
+ ActiveRecord.version.release < Gem::Version.new('6.0.0')
138
+ end
139
+
122
140
  def migrate
123
141
  if activerecord_below_5_2?
124
142
  ActiveRecord::Migrator.migrate('spec/dummy/db/migrate')
125
- else
143
+ elsif activerecord_below_6_0?
126
144
  ActiveRecord::MigrationContext.new('spec/dummy/db/migrate').migrate
145
+ else
146
+ # TODO: Figure out if there is any other possibility that can/should be
147
+ # passed here as the second argument for the migration context
148
+ ActiveRecord::MigrationContext.new('spec/dummy/db/migrate', ActiveRecord::SchemaMigration).migrate
127
149
  end
128
150
  end
@@ -1,46 +1,54 @@
1
- # -*- encoding: utf-8 -*-
2
- $: << File.expand_path("../lib", __FILE__)
3
- require "apartment/version"
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH << File.expand_path('lib', __dir__)
4
+ require 'apartment/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = %q{ros-apartment}
7
+ s.name = 'ros-apartment'
7
8
  s.version = Apartment::VERSION
8
9
 
9
- s.authors = ["Ryan Brunner", "Brad Robertson"]
10
- s.summary = %q{A Ruby gem for managing database multitenancy}
11
- s.description = %q{Apartment allows Rack applications to deal with database multitenancy through ActiveRecord}
12
- s.email = ["ryan@influitive.com", "brad@influitive.com"]
13
- s.files = `git ls-files`.split($/)
14
- s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
10
+ s.authors = ['Ryan Brunner', 'Brad Robertson', 'Rui Baltazar']
11
+ s.summary = 'A Ruby gem for managing database multitenancy. Apartment Gem drop in replacement'
12
+ s.description = 'Apartment allows Rack applications to deal with database multitenancy through ActiveRecord'
13
+ s.email = ['ryan@influitive.com', 'brad@influitive.com', 'rui.p.baltazar@gmail.com']
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been
16
+ # added into git.
17
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject do |f|
19
+ # NOTE: ignore all test related
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ end
23
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
15
24
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
- s.require_paths = ["lib"]
25
+ s.require_paths = ['lib']
17
26
 
18
- s.homepage = %q{https://github.com/rails-on-services/apartment}
19
- s.licenses = ["MIT"]
27
+ s.homepage = 'https://github.com/rails-on-services/apartment'
28
+ s.licenses = ['MIT']
20
29
 
21
30
  # must be >= 3.1.2 due to bug in prepared_statements
22
- s.add_dependency 'activerecord', '>= 3.1.2', '< 6.1'
23
- s.add_dependency 'rack', '>= 1.3.6'
24
- s.add_dependency 'public_suffix', '>= 2'
25
- s.add_dependency 'parallel', '>= 0.7.1'
31
+ s.add_dependency 'activerecord', '>= 5.0.0', '< 6.1'
32
+ s.add_dependency 'parallel', '< 2.0'
33
+ s.add_dependency 'public_suffix', '>= 2.0.5', '< 5.0'
34
+ s.add_dependency 'rack', '>= 1.3.6', '< 3.0'
26
35
 
27
- s.add_development_dependency 'appraisal'
36
+ s.add_development_dependency 'appraisal', '~> 2.2'
37
+ s.add_development_dependency 'bundler', '>= 1.3', '< 3.0'
38
+ s.add_development_dependency 'capybara', '~> 2.0'
28
39
  s.add_development_dependency 'rake', '~> 0.9'
29
40
  s.add_development_dependency 'rspec', '~> 3.4'
30
41
  s.add_development_dependency 'rspec-rails', '~> 3.4'
31
- s.add_development_dependency 'capybara', '~> 2.0'
32
- s.add_development_dependency 'bundler', '>= 1.3', '< 2.0'
33
42
 
34
43
  if defined?(JRUBY_VERSION)
35
44
  s.add_development_dependency 'activerecord-jdbc-adapter'
36
- s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
37
45
  s.add_development_dependency 'activerecord-jdbcmysql-adapter'
38
- s.add_development_dependency 'jdbc-postgres'
46
+ s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
39
47
  s.add_development_dependency 'jdbc-mysql'
40
- s.add_development_dependency 'jruby-openssl'
48
+ s.add_development_dependency 'jdbc-postgres'
41
49
  else
42
- s.add_development_dependency 'mysql2'
43
- s.add_development_dependency 'pg'
50
+ s.add_development_dependency 'mysql2', '~> 0.5'
51
+ s.add_development_dependency 'pg', '~> 1.2'
44
52
  s.add_development_dependency 'sqlite3', '~> 1.3.6'
45
53
  end
46
54
  end
@@ -1,23 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by Appraisal
2
4
 
3
- source "http://rubygems.org"
5
+ source 'http://rubygems.org'
4
6
 
5
- gem "rails", "~> 4.2.0"
7
+ gem 'rails', '~> 4.2.0'
6
8
 
7
9
  group :local do
8
- gem "pry"
9
- gem "guard-rspec", "~> 4.2"
10
+ gem 'guard-rspec', '~> 4.2'
11
+ gem 'pry'
10
12
  end
11
13
 
12
14
  platforms :ruby do
13
- gem "pg", "< 1.0.0"
14
- gem "mysql2", "~> 0.4.0"
15
+ gem 'mysql2', '~> 0.4.0'
16
+ gem 'pg', '< 1.0.0'
15
17
  end
16
18
 
17
19
  platforms :jruby do
18
- gem "activerecord-jdbc-adapter", "~> 1.3"
19
- gem "activerecord-jdbcpostgresql-adapter", "~> 1.3"
20
- gem "activerecord-jdbcmysql-adapter", "~> 1.3"
20
+ gem 'activerecord-jdbc-adapter', '~> 1.3'
21
+ gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
22
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
21
23
  end
22
24
 
23
- gemspec path: "../"
25
+ gemspec path: '../'
@@ -2,11 +2,12 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
+ gem "perx-rubocop", "~> 0.0.3"
5
6
  gem "rails", "~> 5.0.0"
6
7
 
7
8
  group :local do
8
- gem "pry"
9
9
  gem "guard-rspec", "~> 4.2"
10
+ gem "pry"
10
11
  end
11
12
 
12
13
  platforms :ruby do
@@ -2,11 +2,12 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
+ gem "perx-rubocop", "~> 0.0.3"
5
6
  gem "rails", "~> 5.1.0"
6
7
 
7
8
  group :local do
8
- gem "pry"
9
9
  gem "guard-rspec", "~> 4.2"
10
+ gem "pry"
10
11
  end
11
12
 
12
13
  platforms :ruby do
@@ -2,11 +2,12 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
+ gem "perx-rubocop", "~> 0.0.3"
5
6
  gem "rails", "~> 5.2.0"
6
7
 
7
8
  group :local do
8
- gem "pry"
9
9
  gem "guard-rspec", "~> 4.2"
10
+ gem "pry"
10
11
  end
11
12
 
12
13
  platforms :jruby do
@@ -2,11 +2,12 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 6.0.0.rc1"
5
+ gem "perx-rubocop", "~> 0.0.3"
6
+ gem "rails", "~> 6.0.0"
6
7
 
7
8
  group :local do
8
- gem "pry"
9
9
  gem "guard-rspec", "~> 4.2"
10
+ gem "pry"
10
11
  end
11
12
 
12
13
  platforms :ruby do
@@ -14,9 +15,9 @@ platforms :ruby do
14
15
  end
15
16
 
16
17
  platforms :jruby do
17
- gem "activerecord-jdbc-adapter", "~> 60.0.rc1"
18
- gem "activerecord-jdbcpostgresql-adapter", "~> 60.0.rc1"
19
- gem "activerecord-jdbcmysql-adapter", "~> 60.0.rc1"
18
+ gem "activerecord-jdbc-adapter", "~> 60.0"
19
+ gem "activerecord-jdbcpostgresql-adapter", "~> 60.0"
20
+ gem "activerecord-jdbcmysql-adapter", "~> 60.0"
20
21
  end
21
22
 
22
23
  gemspec path: "../"
@@ -2,11 +2,12 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
+ gem "perx-rubocop", "~> 0.0.3"
5
6
  gem "rails", git: "https://github.com/rails/rails.git"
6
7
 
7
8
  group :local do
8
- gem "pry"
9
9
  gem "guard-rspec", "~> 4.2"
10
+ gem "pry"
10
11
  end
11
12
 
12
13
  platforms :ruby do
@@ -1,22 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'apartment/railtie' if defined?(Rails)
2
4
  require 'active_support/core_ext/object/blank'
3
5
  require 'forwardable'
4
6
  require 'active_record'
5
7
  require 'apartment/tenant'
6
8
 
7
- module Apartment
9
+ # require_relative 'apartment/arel/visitors/postgresql'
8
10
 
9
- class << self
11
+ require_relative 'apartment/active_record/connection_handling' if ActiveRecord.version.release >= Gem::Version.new('6.0')
10
12
 
13
+ if ActiveRecord.version.release >= Gem::Version.new('6.1')
14
+ require_relative 'apartment/active_record/schema_migration'
15
+ require_relative 'apartment/active_record/internal_metadata'
16
+ end
17
+
18
+ module Apartment
19
+ class << self
11
20
  extend Forwardable
12
21
 
13
- ACCESSOR_METHODS = [:use_schemas, :use_sql, :seed_after_create, :prepend_environment, :append_environment, :with_multi_server_setup]
14
- WRITER_METHODS = [:tenant_names, :database_schema_file, :excluded_models, :default_schema, :persistent_schemas, :connection_class, :tld_length, :db_migrate_tenants, :seed_data_file, :parallel_migration_threads, :pg_excluded_names]
22
+ ACCESSOR_METHODS = %i[use_schemas use_sql seed_after_create prepend_environment
23
+ append_environment with_multi_server_setup tenant_presence_check].freeze
24
+
25
+ WRITER_METHODS = %i[tenant_names database_schema_file excluded_models
26
+ default_schema persistent_schemas connection_class
27
+ tld_length db_migrate_tenants seed_data_file
28
+ parallel_migration_threads pg_excluded_names].freeze
15
29
 
16
30
  attr_accessor(*ACCESSOR_METHODS)
17
31
  attr_writer(*WRITER_METHODS)
18
32
 
19
- def_delegators :connection_class, :connection, :connection_config, :establish_connection
33
+ if ActiveRecord.version.release >= Gem::Version.new('6.1')
34
+ def_delegators :connection_class, :connection, :connection_db_config, :establish_connection
35
+
36
+ def connection_config
37
+ connection_db_config.configuration_hash
38
+ end
39
+ else
40
+ def_delegators :connection_class, :connection, :connection_config, :establish_connection
41
+ end
20
42
 
21
43
  # configure apartment with available options
22
44
  def configure
@@ -32,7 +54,7 @@ module Apartment
32
54
  end
33
55
 
34
56
  def db_config_for(tenant)
35
- (tenants_with_config[tenant] || connection_config).with_indifferent_access
57
+ (tenants_with_config[tenant] || connection_config)
36
58
  end
37
59
 
38
60
  # Whether or not db:migrate should also migrate tenants
@@ -49,14 +71,14 @@ module Apartment
49
71
  end
50
72
 
51
73
  def default_schema
52
- @default_schema || "public" # TODO 'public' is postgres specific
74
+ @default_schema || 'public' # TODO: 'public' is postgres specific
53
75
  end
54
76
 
55
77
  def parallel_migration_threads
56
78
  @parallel_migration_threads || 0
57
79
  end
58
- alias :default_tenant :default_schema
59
- alias :default_tenant= :default_schema=
80
+ alias default_tenant default_schema
81
+ alias default_tenant= default_schema=
60
82
 
61
83
  def persistent_schemas
62
84
  @persistent_schemas || []
@@ -75,7 +97,7 @@ module Apartment
75
97
  def seed_data_file
76
98
  return @seed_data_file if defined?(@seed_data_file)
77
99
 
78
- @seed_data_file = "#{Rails.root}/db/seeds.rb"
100
+ @seed_data_file = Rails.root.join('db', 'seeds.rb')
79
101
  end
80
102
 
81
103
  def pg_excluded_names
@@ -84,11 +106,14 @@ module Apartment
84
106
 
85
107
  # Reset all the config for Apartment
86
108
  def reset
87
- (ACCESSOR_METHODS + WRITER_METHODS).each{|method| remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}") }
109
+ (ACCESSOR_METHODS + WRITER_METHODS).each do |method|
110
+ remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}")
111
+ end
88
112
  end
89
113
 
90
114
  def extract_tenant_config
91
115
  return {} unless @tenant_names
116
+
92
117
  values = @tenant_names.respond_to?(:call) ? @tenant_names.call : @tenant_names
93
118
  unless values.is_a? Hash
94
119
  values = values.each_with_object({}) do |tenant, hash|