ros-apartment 2.3.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pryrc +5 -3
- data/.rubocop.yml +22 -0
- data/.rubocop_todo.yml +29 -0
- data/.story_branch.yml +5 -0
- data/.travis.yml +20 -36
- data/Appraisals +16 -29
- data/Gemfile +5 -2
- data/Guardfile +3 -1
- data/HISTORY.md +57 -0
- data/README.md +64 -21
- data/Rakefile +36 -22
- data/TODO.md +0 -1
- data/apartment.gemspec +17 -10
- data/gemfiles/rails_4_2.gemfile +12 -10
- data/gemfiles/rails_5_0.gemfile +2 -1
- data/gemfiles/rails_5_1.gemfile +2 -1
- data/gemfiles/rails_5_2.gemfile +2 -1
- data/gemfiles/rails_6_0.gemfile +6 -5
- data/gemfiles/rails_master.gemfile +2 -1
- data/lib/apartment.rb +38 -14
- data/lib/apartment/active_record/connection_handling.rb +17 -0
- data/lib/apartment/active_record/internal_metadata.rb +11 -0
- data/lib/apartment/active_record/log_subscriber.rb +41 -0
- data/lib/apartment/active_record/schema_migration.rb +13 -0
- data/lib/apartment/adapters/abstract_adapter.rb +49 -45
- data/lib/apartment/adapters/abstract_jdbc_adapter.rb +4 -3
- data/lib/apartment/adapters/jdbc_mysql_adapter.rb +3 -3
- data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +20 -13
- data/lib/apartment/adapters/mysql2_adapter.rb +12 -9
- data/lib/apartment/adapters/postgis_adapter.rb +3 -2
- data/lib/apartment/adapters/postgresql_adapter.rb +59 -27
- data/lib/apartment/adapters/sqlite3_adapter.rb +18 -8
- data/lib/apartment/console.rb +35 -3
- data/lib/apartment/custom_console.rb +42 -0
- data/lib/apartment/deprecation.rb +2 -1
- data/lib/apartment/elevators/domain.rb +4 -3
- data/lib/apartment/elevators/first_subdomain.rb +3 -2
- data/lib/apartment/elevators/generic.rb +4 -3
- data/lib/apartment/elevators/host.rb +6 -1
- data/lib/apartment/elevators/host_hash.rb +6 -2
- data/lib/apartment/elevators/subdomain.rb +9 -5
- data/lib/apartment/migrator.rb +4 -3
- data/lib/apartment/model.rb +27 -0
- data/lib/apartment/railtie.rb +27 -15
- data/lib/apartment/reloader.rb +2 -1
- data/lib/apartment/tasks/enhancements.rb +4 -6
- data/lib/apartment/tasks/task_helper.rb +35 -0
- data/lib/apartment/tenant.rb +19 -9
- data/lib/apartment/version.rb +3 -1
- data/lib/generators/apartment/install/install_generator.rb +4 -3
- data/lib/generators/apartment/install/templates/apartment.rb +8 -2
- data/lib/tasks/apartment.rake +22 -44
- metadata +51 -230
- data/spec/adapters/jdbc_mysql_adapter_spec.rb +0 -19
- data/spec/adapters/jdbc_postgresql_adapter_spec.rb +0 -41
- data/spec/adapters/mysql2_adapter_spec.rb +0 -59
- data/spec/adapters/postgresql_adapter_spec.rb +0 -61
- data/spec/adapters/sqlite3_adapter_spec.rb +0 -83
- data/spec/apartment_spec.rb +0 -11
- data/spec/config/database.yml.sample +0 -49
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/controllers/application_controller.rb +0 -6
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/company.rb +0 -3
- data/spec/dummy/app/models/user.rb +0 -3
- data/spec/dummy/app/views/application/index.html.erb +0 -1
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -49
- data/spec/dummy/config/boot.rb +0 -11
- data/spec/dummy/config/database.yml.sample +0 -44
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -28
- data/spec/dummy/config/environments/production.rb +0 -51
- data/spec/dummy/config/environments/test.rb +0 -34
- data/spec/dummy/config/initializers/apartment.rb +0 -4
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -10
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -3
- data/spec/dummy/db/migrate/20110613152810_create_dummy_models.rb +0 -39
- data/spec/dummy/db/migrate/20111202022214_create_table_books.rb +0 -14
- data/spec/dummy/db/migrate/20180415260934_create_public_tokens.rb +0 -13
- data/spec/dummy/db/schema.rb +0 -55
- data/spec/dummy/db/seeds.rb +0 -5
- data/spec/dummy/db/seeds/import.rb +0 -5
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -26
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy_engine/.gitignore +0 -8
- data/spec/dummy_engine/Gemfile +0 -15
- data/spec/dummy_engine/Rakefile +0 -34
- data/spec/dummy_engine/bin/rails +0 -12
- data/spec/dummy_engine/config/initializers/apartment.rb +0 -51
- data/spec/dummy_engine/dummy_engine.gemspec +0 -24
- data/spec/dummy_engine/lib/dummy_engine.rb +0 -4
- data/spec/dummy_engine/lib/dummy_engine/engine.rb +0 -4
- data/spec/dummy_engine/lib/dummy_engine/version.rb +0 -3
- data/spec/dummy_engine/test/dummy/Rakefile +0 -6
- data/spec/dummy_engine/test/dummy/config.ru +0 -4
- data/spec/dummy_engine/test/dummy/config/application.rb +0 -22
- data/spec/dummy_engine/test/dummy/config/boot.rb +0 -5
- data/spec/dummy_engine/test/dummy/config/database.yml +0 -25
- data/spec/dummy_engine/test/dummy/config/environment.rb +0 -5
- data/spec/dummy_engine/test/dummy/config/environments/development.rb +0 -37
- data/spec/dummy_engine/test/dummy/config/environments/production.rb +0 -78
- data/spec/dummy_engine/test/dummy/config/environments/test.rb +0 -39
- data/spec/dummy_engine/test/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy_engine/test/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy_engine/test/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy_engine/test/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy_engine/test/dummy/config/locales/en.yml +0 -23
- data/spec/dummy_engine/test/dummy/config/routes.rb +0 -56
- data/spec/dummy_engine/test/dummy/config/secrets.yml +0 -22
- data/spec/examples/connection_adapter_examples.rb +0 -42
- data/spec/examples/generic_adapter_custom_configuration_example.rb +0 -95
- data/spec/examples/generic_adapter_examples.rb +0 -163
- data/spec/examples/schema_adapter_examples.rb +0 -234
- data/spec/integration/apartment_rake_integration_spec.rb +0 -107
- data/spec/integration/query_caching_spec.rb +0 -81
- data/spec/integration/use_within_an_engine_spec.rb +0 -28
- data/spec/schemas/v1.rb +0 -16
- data/spec/schemas/v2.rb +0 -43
- data/spec/schemas/v3.rb +0 -49
- data/spec/spec_helper.rb +0 -61
- data/spec/support/apartment_helpers.rb +0 -43
- data/spec/support/capybara_sessions.rb +0 -15
- data/spec/support/config.rb +0 -10
- data/spec/support/contexts.rb +0 -52
- data/spec/support/requirements.rb +0 -35
- data/spec/support/setup.rb +0 -46
- data/spec/tasks/apartment_rake_spec.rb +0 -129
- data/spec/tenant_spec.rb +0 -190
- data/spec/unit/config_spec.rb +0 -112
- data/spec/unit/elevators/domain_spec.rb +0 -32
- data/spec/unit/elevators/first_subdomain_spec.rb +0 -24
- data/spec/unit/elevators/generic_spec.rb +0 -54
- data/spec/unit/elevators/host_hash_spec.rb +0 -32
- data/spec/unit/elevators/host_spec.rb +0 -89
- data/spec/unit/elevators/subdomain_spec.rb +0 -76
- data/spec/unit/migrator_spec.rb +0 -77
- data/spec/unit/reloader_spec.rb +0 -24
data/Rakefile
CHANGED
@@ -1,19 +1,25 @@
|
|
1
|
-
|
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
|
8
|
-
require
|
13
|
+
require 'rspec'
|
14
|
+
require 'rspec/core/rake_task'
|
9
15
|
|
10
|
-
RSpec::Core::RakeTask.new(:
|
11
|
-
spec.pattern =
|
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
|
-
[
|
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 :
|
36
|
+
task default: :spec
|
31
37
|
|
32
38
|
namespace :db do
|
33
39
|
namespace :test do
|
34
|
-
task :
|
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, :
|
44
|
-
FileUtils.copy(rails_db_file + '.sample', 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
|
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 <<
|
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
|
-
|
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
|
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
|
-
|
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
|
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
|
-
|
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
|
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
|
-
|
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
|
data/TODO.md
CHANGED
data/apartment.gemspec
CHANGED
@@ -11,7 +11,15 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = 'A Ruby gem for managing database multitenancy. Apartment Gem drop in replacement'
|
12
12
|
s.description = 'Apartment allows Rack applications to deal with database multitenancy through ActiveRecord'
|
13
13
|
s.email = ['ryan@influitive.com', 'brad@influitive.com', 'rui.p.baltazar@gmail.com']
|
14
|
-
|
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
|
15
23
|
s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
16
24
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
25
|
s.require_paths = ['lib']
|
@@ -20,13 +28,13 @@ Gem::Specification.new do |s|
|
|
20
28
|
s.licenses = ['MIT']
|
21
29
|
|
22
30
|
# must be >= 3.1.2 due to bug in prepared_statements
|
23
|
-
s.add_dependency 'activerecord', '>=
|
24
|
-
s.add_dependency 'parallel', '
|
25
|
-
s.add_dependency 'public_suffix', '>= 2'
|
26
|
-
s.add_dependency 'rack', '>= 1.3.6'
|
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'
|
27
35
|
|
28
|
-
s.add_development_dependency 'appraisal'
|
29
|
-
s.add_development_dependency 'bundler', '>= 1.3', '<
|
36
|
+
s.add_development_dependency 'appraisal', '~> 2.2'
|
37
|
+
s.add_development_dependency 'bundler', '>= 1.3', '< 3.0'
|
30
38
|
s.add_development_dependency 'capybara', '~> 2.0'
|
31
39
|
s.add_development_dependency 'rake', '~> 0.9'
|
32
40
|
s.add_development_dependency 'rspec', '~> 3.4'
|
@@ -38,10 +46,9 @@ Gem::Specification.new do |s|
|
|
38
46
|
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
|
39
47
|
s.add_development_dependency 'jdbc-mysql'
|
40
48
|
s.add_development_dependency 'jdbc-postgres'
|
41
|
-
s.add_development_dependency 'jruby-openssl'
|
42
49
|
else
|
43
|
-
s.add_development_dependency 'mysql2'
|
44
|
-
s.add_development_dependency 'pg'
|
50
|
+
s.add_development_dependency 'mysql2', '~> 0.5'
|
51
|
+
s.add_development_dependency 'pg', '~> 1.2'
|
45
52
|
s.add_development_dependency 'sqlite3', '~> 1.3.6'
|
46
53
|
end
|
47
54
|
end
|
data/gemfiles/rails_4_2.gemfile
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file was generated by Appraisal
|
2
4
|
|
3
|
-
source
|
5
|
+
source 'http://rubygems.org'
|
4
6
|
|
5
|
-
gem
|
7
|
+
gem 'rails', '~> 4.2.0'
|
6
8
|
|
7
9
|
group :local do
|
8
|
-
gem
|
9
|
-
gem
|
10
|
+
gem 'guard-rspec', '~> 4.2'
|
11
|
+
gem 'pry'
|
10
12
|
end
|
11
13
|
|
12
14
|
platforms :ruby do
|
13
|
-
gem
|
14
|
-
gem
|
15
|
+
gem 'mysql2', '~> 0.4.0'
|
16
|
+
gem 'pg', '< 1.0.0'
|
15
17
|
end
|
16
18
|
|
17
19
|
platforms :jruby do
|
18
|
-
gem
|
19
|
-
gem
|
20
|
-
gem
|
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: '../'
|
data/gemfiles/rails_5_0.gemfile
CHANGED
data/gemfiles/rails_5_1.gemfile
CHANGED
data/gemfiles/rails_5_2.gemfile
CHANGED
data/gemfiles/rails_6_0.gemfile
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
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
|
18
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 60.0
|
19
|
-
gem "activerecord-jdbcmysql-adapter", "~> 60.0
|
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: "../"
|
data/lib/apartment.rb
CHANGED
@@ -1,22 +1,45 @@
|
|
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
|
-
|
9
|
+
# require_relative 'apartment/arel/visitors/postgresql'
|
8
10
|
|
9
|
-
|
11
|
+
require_relative 'apartment/active_record/log_subscriber'
|
12
|
+
require_relative 'apartment/active_record/connection_handling' if ActiveRecord.version.release >= Gem::Version.new('6.0')
|
13
|
+
|
14
|
+
if ActiveRecord.version.release >= Gem::Version.new('6.1')
|
15
|
+
require_relative 'apartment/active_record/schema_migration'
|
16
|
+
require_relative 'apartment/active_record/internal_metadata'
|
17
|
+
end
|
10
18
|
|
19
|
+
module Apartment
|
20
|
+
class << self
|
11
21
|
extend Forwardable
|
12
22
|
|
13
|
-
ACCESSOR_METHODS
|
14
|
-
|
23
|
+
ACCESSOR_METHODS = %i[use_schemas use_sql seed_after_create prepend_environment default_tenant
|
24
|
+
append_environment with_multi_server_setup tenant_presence_check active_record_log].freeze
|
25
|
+
|
26
|
+
WRITER_METHODS = %i[tenant_names database_schema_file excluded_models
|
27
|
+
persistent_schemas connection_class
|
28
|
+
db_migrate_tenants seed_data_file
|
29
|
+
parallel_migration_threads pg_excluded_names].freeze
|
15
30
|
|
16
31
|
attr_accessor(*ACCESSOR_METHODS)
|
17
32
|
attr_writer(*WRITER_METHODS)
|
18
33
|
|
19
|
-
|
34
|
+
if ActiveRecord.version.release >= Gem::Version.new('6.1')
|
35
|
+
def_delegators :connection_class, :connection, :connection_db_config, :establish_connection
|
36
|
+
|
37
|
+
def connection_config
|
38
|
+
connection_db_config.configuration_hash
|
39
|
+
end
|
40
|
+
else
|
41
|
+
def_delegators :connection_class, :connection, :connection_config, :establish_connection
|
42
|
+
end
|
20
43
|
|
21
44
|
# configure apartment with available options
|
22
45
|
def configure
|
@@ -31,8 +54,12 @@ module Apartment
|
|
31
54
|
extract_tenant_config
|
32
55
|
end
|
33
56
|
|
57
|
+
def tld_length=(_)
|
58
|
+
Apartment::Deprecation.warn('`config.tld_length` have no effect because it was removed in https://github.com/influitive/apartment/pull/309')
|
59
|
+
end
|
60
|
+
|
34
61
|
def db_config_for(tenant)
|
35
|
-
(tenants_with_config[tenant] || connection_config)
|
62
|
+
(tenants_with_config[tenant] || connection_config)
|
36
63
|
end
|
37
64
|
|
38
65
|
# Whether or not db:migrate should also migrate tenants
|
@@ -48,15 +75,9 @@ module Apartment
|
|
48
75
|
@excluded_models || []
|
49
76
|
end
|
50
77
|
|
51
|
-
def default_schema
|
52
|
-
@default_schema || "public" # TODO 'public' is postgres specific
|
53
|
-
end
|
54
|
-
|
55
78
|
def parallel_migration_threads
|
56
79
|
@parallel_migration_threads || 0
|
57
80
|
end
|
58
|
-
alias :default_tenant :default_schema
|
59
|
-
alias :default_tenant= :default_schema=
|
60
81
|
|
61
82
|
def persistent_schemas
|
62
83
|
@persistent_schemas || []
|
@@ -75,7 +96,7 @@ module Apartment
|
|
75
96
|
def seed_data_file
|
76
97
|
return @seed_data_file if defined?(@seed_data_file)
|
77
98
|
|
78
|
-
@seed_data_file =
|
99
|
+
@seed_data_file = Rails.root.join('db', 'seeds.rb')
|
79
100
|
end
|
80
101
|
|
81
102
|
def pg_excluded_names
|
@@ -84,11 +105,14 @@ module Apartment
|
|
84
105
|
|
85
106
|
# Reset all the config for Apartment
|
86
107
|
def reset
|
87
|
-
(ACCESSOR_METHODS + WRITER_METHODS).each
|
108
|
+
(ACCESSOR_METHODS + WRITER_METHODS).each do |method|
|
109
|
+
remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}")
|
110
|
+
end
|
88
111
|
end
|
89
112
|
|
90
113
|
def extract_tenant_config
|
91
114
|
return {} unless @tenant_names
|
115
|
+
|
92
116
|
values = @tenant_names.respond_to?(:call) ? @tenant_names.call : @tenant_names
|
93
117
|
unless values.is_a? Hash
|
94
118
|
values = values.each_with_object({}) do |tenant, hash|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionHandling
|
5
|
+
def connected_to_with_tenant(database: nil, role: nil, prevent_writes: false, &blk)
|
6
|
+
current_tenant = Apartment::Tenant.current
|
7
|
+
|
8
|
+
connected_to_without_tenant(database: database, role: role, prevent_writes: prevent_writes) do
|
9
|
+
Apartment::Tenant.switch!(current_tenant)
|
10
|
+
yield(blk)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
alias connected_to_without_tenant connected_to
|
15
|
+
alias connected_to connected_to_with_tenant
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Rails/ApplicationRecord
|
4
|
+
class InternalMetadata < ActiveRecord::Base # :nodoc:
|
5
|
+
class << self
|
6
|
+
def table_exists?
|
7
|
+
connection.table_exists?(table_name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
# rubocop:enable Rails/ApplicationRecord
|