ros-apartment 2.3.0.alpha2 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34315580882fc1aba022c3e274f51e72c3cd5feef66f655dad4ce82cacec1aa3
4
- data.tar.gz: 7e970b07d5467167efc9b49e6d7f8b69c0f28c2fbccff63f0137e5b7664b0b4f
3
+ metadata.gz: e57016e050d57190e3baa0693ccd7e2e094db1cdb864f9c75e193ce06fcdddbb
4
+ data.tar.gz: 65b587e5c59e03e957e42c8ca0c0cf4d078859e078eebdcda4594e69284c3175
5
5
  SHA512:
6
- metadata.gz: 3b77d009ba12644e49099928f74811a5ca56d6142a08c35cbd21fc34d1aa0c6fc1e94a8165aae35593b235bffb81dccb9627f44bdc7944e6470e6c123db8c3b7
7
- data.tar.gz: 1590e8e67d2af1651986c2ce19da2d3aaa474e30f37b1039b59ca1bb302c24124e4eacf320fb7c11b6a415957bb7130ed108959dc3deebc6663c8b78d8349262
6
+ metadata.gz: d1ebfaf0a5e4da01bceed2f3cec330aefec6bbfdb5e98dd706ec7b0305cb8bc820e58106ebb60854fc7f5d8735c02d426c87a17a9f16c4b12f34104059644419
7
+ data.tar.gz: 1a72b322cf5913313aedfb1f84d3117c5cbbd5ba36a7b62ab1cf10d2e3987d8eca8b465cfc38538b86482a08fd8412e43e1d39708d3a952e4fad8c946b0b0203
@@ -0,0 +1,22 @@
1
+ name: Rubocop Lint
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ container:
11
+ image: ruby:2.6.5
12
+
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+ - name: Rubocop Linter
16
+ uses: andrewmcodes/rubocop-linter-action@v2.0.0
17
+ with:
18
+ additional_gems: 'perx-rubocop:0.0.3'
19
+ fail_level: 'warning'
20
+ version: '0.77.0'
21
+ env:
22
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
data/.pryrc CHANGED
@@ -1,3 +1,5 @@
1
- if defined?(Rails) && Rails.env
2
- extend Rails::ConsoleMethods
3
- end
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Style/MixinUsage
4
+ extend Rails::ConsoleMethods if defined?(Rails) && Rails.env
5
+ # rubocop:enable Style/MixinUsage
@@ -0,0 +1,21 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ inherit_gem:
4
+ perx-rubocop:
5
+ - default.yml
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - 'gemfiles/**/*.gemfile'
10
+
11
+ Style/WordArray:
12
+ Exclude:
13
+ - spec/schemas/**/*.rb
14
+
15
+ Style/NumericLiterals:
16
+ Exclude:
17
+ - spec/schemas/**/*.rb
18
+
19
+ Layout/EmptyLineAfterMagicComment:
20
+ Exclude:
21
+ - spec/schemas/**/*.rb
@@ -0,0 +1,29 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-02-16 15:36:55 +0800 using RuboCop version 0.77.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 5
10
+ Metrics/AbcSize:
11
+ Max: 33
12
+
13
+ # Offense count: 11
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ # ExcludedMethods: refine
16
+ Metrics/BlockLength:
17
+ Max: 176
18
+
19
+ # Offense count: 18
20
+ # Cop supports --auto-correct.
21
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
22
+ # URISchemes: http, https
23
+ Metrics/LineLength:
24
+ Max: 200
25
+
26
+ # Offense count: 4
27
+ # Configuration parameters: CountComments, ExcludedMethods.
28
+ Metrics/MethodLength:
29
+ Max: 24
@@ -0,0 +1,4 @@
1
+ ---
2
+ tracker: github
3
+ project_id:
4
+ - rails-on-services/apartment
@@ -4,62 +4,41 @@ language: ruby
4
4
  services:
5
5
  - docker
6
6
  rvm:
7
- - jruby-9.1.17.0
8
- - 2.1.9
9
- - 2.2.9
10
- - 2.3.6
11
- - 2.4.3
12
- - 2.5.0
13
- - 2.6.2
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
14
13
  - ruby-head
14
+
15
+ branches:
16
+ only:
17
+ - master
18
+ - development
19
+
15
20
  gemfile:
16
- - gemfiles/rails_4_2.gemfile
17
21
  - gemfiles/rails_5_0.gemfile
18
22
  - gemfiles/rails_5_1.gemfile
19
23
  - gemfiles/rails_5_2.gemfile
20
24
  - gemfiles/rails_6_0.gemfile
21
25
  - gemfiles/rails_master.gemfile
26
+
22
27
  bundler_args: --without local
23
28
  before_install:
24
29
  - sudo /etc/init.d/mysql stop
25
30
  - sudo /etc/init.d/postgresql stop
26
31
  - docker-compose up -d
27
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
28
- - gem uninstall bundler -v '>= 2' -x || true
29
- - gem install bundler -v '< 2'
30
32
  env:
31
33
  RUBY_GC_MALLOC_LIMIT: 90000000
32
34
  RUBY_GC_HEAP_FREE_SLOTS: 200000
33
35
  jobs:
34
36
  allow_failures:
35
37
  - rvm: ruby-head
38
+ - rvm: jruby-head
36
39
  - gemfile: gemfiles/rails_master.gemfile
37
- - rvm: jruby-9.1.17.0
38
- gemfile: gemfiles/rails_5_0.gemfile
39
40
  exclude:
40
- - rvm: 2.1.9
41
- gemfile: gemfiles/rails_5_0.gemfile
42
- - rvm: 2.1.9
43
- gemfile: gemfiles/rails_5_1.gemfile
44
- - rvm: 2.1.9
45
- gemfile: gemfiles/rails_5_2.gemfile
46
- - rvm: 2.1.9
47
- gemfile: gemfiles/rails_6_0.gemfile
48
- - rvm: 2.1.9
49
- gemfile: gemfiles/rails_master.gemfile
50
- - rvm: 2.2.9
51
- gemfile: gemfiles/rails_6_0.gemfile
52
- - rvm: 2.3.6
53
- gemfile: gemfiles/rails_6_0.gemfile
54
- - rvm: 2.4.3
55
- gemfile: gemfiles/rails_6_0.gemfile
56
- - rvm: jruby-9.1.17.0
57
- gemfile: gemfiles/rails_5_1.gemfile
58
- - rvm: jruby-9.1.17.0
59
- gemfile: gemfiles/rails_5_2.gemfile
60
- - rvm: jruby-9.1.17.0
41
+ - rvm: 2.4.10
61
42
  gemfile: gemfiles/rails_6_0.gemfile
62
- - rvm: jruby-9.1.17.0
63
- gemfile: gemfiles/rails_master.gemfile
64
43
  fast_finish: true
65
44
  cache: bundler
data/Appraisals CHANGED
@@ -1,20 +1,9 @@
1
- appraise "rails-4-2" do
2
- gem "rails", "~> 4.2.0"
3
- platforms :ruby do
4
- gem "pg", "< 1.0.0"
5
- gem "mysql2", "~> 0.4.0"
6
- end
7
- platforms :jruby do
8
- gem 'activerecord-jdbc-adapter', '~> 1.3'
9
- gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
10
- gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
11
- end
12
- end
1
+ # frozen_string_literal: true
13
2
 
14
- appraise "rails-5-0" do
15
- gem "rails", "~> 5.0.0"
3
+ appraise 'rails-5-0' do
4
+ gem 'rails', '~> 5.0.0'
16
5
  platforms :ruby do
17
- gem "pg", "< 1.0.0"
6
+ gem 'pg', '< 1.0.0'
18
7
  end
19
8
  platforms :jruby do
20
9
  gem 'activerecord-jdbc-adapter', '~> 50.0'
@@ -23,10 +12,10 @@ appraise "rails-5-0" do
23
12
  end
24
13
  end
25
14
 
26
- appraise "rails-5-1" do
27
- gem "rails", "~> 5.1.0"
15
+ appraise 'rails-5-1' do
16
+ gem 'rails', '~> 5.1.0'
28
17
  platforms :ruby do
29
- gem "pg", "< 1.0.0"
18
+ gem 'pg', '< 1.0.0'
30
19
  end
31
20
  platforms :jruby do
32
21
  gem 'activerecord-jdbc-adapter', '~> 51.0'
@@ -35,8 +24,8 @@ appraise "rails-5-1" do
35
24
  end
36
25
  end
37
26
 
38
- appraise "rails-5-2" do
39
- gem "rails", "~> 5.2.0"
27
+ appraise 'rails-5-2' do
28
+ gem 'rails', '~> 5.2.0'
40
29
  platforms :jruby do
41
30
  gem 'activerecord-jdbc-adapter', '~> 52.0'
42
31
  gem 'activerecord-jdbcpostgresql-adapter', '~> 52.0'
@@ -44,22 +33,20 @@ appraise "rails-5-2" do
44
33
  end
45
34
  end
46
35
 
47
-
48
- appraise "rails-6-0" do
49
- gem "rails", "~> 6.0.0.rc1"
36
+ appraise 'rails-6-0' do
37
+ gem 'rails', '~> 6.0.0'
50
38
  platforms :ruby do
51
39
  gem 'sqlite3', '~> 1.4'
52
40
  end
53
41
  platforms :jruby do
54
- gem 'activerecord-jdbc-adapter', '~> 60.0.rc1'
55
- gem 'activerecord-jdbcpostgresql-adapter', '~> 60.0.rc1'
56
- gem 'activerecord-jdbcmysql-adapter', '~> 60.0.rc1'
42
+ gem 'activerecord-jdbc-adapter', '~> 60.0'
43
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 60.0'
44
+ gem 'activerecord-jdbcmysql-adapter', '~> 60.0'
57
45
  end
58
46
  end
59
47
 
60
-
61
- appraise "rails-master" do
62
- gem "rails", git: 'https://github.com/rails/rails.git'
48
+ appraise 'rails-master' do
49
+ gem 'rails', git: 'https://github.com/rails/rails.git'
63
50
  platforms :ruby do
64
51
  gem 'sqlite3', '~> 1.4'
65
52
  end
data/Gemfile CHANGED
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
7
+ gem 'perx-rubocop', '~> 0.0.3'
5
8
  gem 'rails', '>= 3.1.2'
6
9
 
7
10
  group :local do
8
- gem 'pry'
9
11
  gem 'guard-rspec', '~> 4.2'
12
+ gem 'pry'
10
13
  end
data/Guardfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Guardfile
2
4
  # More info at https://github.com/guard/guard#readme
3
5
 
@@ -5,7 +7,7 @@ guard :rspec do
5
7
  watch(%r{^spec/.+_spec\.rb$})
6
8
  watch(%r{^lib/apartment/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
7
9
  watch(%r{^lib/apartment/(.+)\.rb$}) { |m| "spec/integration/#{m[1]}_spec.rb" }
8
- watch('spec/spec_helper.rb') { "spec" }
10
+ watch('spec/spec_helper.rb') { 'spec' }
9
11
 
10
12
  # # Rails example
11
13
  # watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
data/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 2.3.0
2
+ * January 3, 2020
3
+
4
+ ## Added
5
+ - Basic support for rails 6
6
+ - Released different gem name, with same API as apartment
7
+
1
8
  # 2.2.1
2
9
  * June 19, 2019
3
10
 
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # Apartment
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/apartment.svg)](https://badge.fury.io/rb/apartment)
4
- [![Code Climate](https://codeclimate.com/github/influitive/apartment/badges/gpa.svg)](https://codeclimate.com/github/influitive/apartment)
5
- [![Build Status](https://travis-ci.org/influitive/apartment.svg?branch=development)](https://travis-ci.org/influitive/apartment)
6
-
7
- # NOT ACTIVELY MAINTAINED YET. SOLELY FOR TESTING PURPOSES ATM
3
+ [![Gem Version](https://badge.fury.io/rb/ros-apartment.svg)](https://badge.fury.io/rb/apartment)
4
+ [![Code Climate](https://api.codeclimate.com/v1/badges/b0dc327380bb8438f991/maintainability)](https://codeclimate.com/github/rails-on-services/apartment/maintainability)
5
+ [![Build Status](https://travis-ci.org/rails-on-services/apartment.svg?branch=development)](https://travis-ci.org/rails-on-services/apartment)
8
6
 
9
7
  *Multitenancy for Rails and ActiveRecord*
10
8
 
@@ -12,26 +10,21 @@ Apartment provides tools to help you deal with multiple tenants in your Rails
12
10
  application. If you need to have certain data sequestered based on account or company,
13
11
  but still allow some data to exist in a common tenant, Apartment can help.
14
12
 
15
- ## HELP!
16
-
17
- In order to help drive the direction of development and clean up the codebase, we'd like to take a poll
18
- on how people are currently using Apartment. If you can take 5 seconds (1 question) to answer
19
- this poll, we'd greatly appreciated it.
20
-
21
- [View Poll](http://www.poll-maker.com/poll391552x4Bfb41a9-15)
13
+ ## Apartment drop in replacement gem
22
14
 
23
- ## Excessive Memory Issues on ActiveRecord 4.x
15
+ After having reached out via github issues and email directly, no replies ever
16
+ came. Since we wanted to upgrade our application to Rails 6 we decided to fork
17
+ and start some development to support Rails 6. Because we don't have access
18
+ to the apartment gem itself, the solution was to release it under a different
19
+ name but providing the exact same API as it was before.
24
20
 
25
- > If you're noticing ever growing memory issues (ie growing with each tenant you add)
26
- > when using Apartment, that's because there's [an issue](https://github.com/rails/rails/issues/19578)
27
- > with how ActiveRecord maps Postgresql data types into AR data types.
28
- > This has been patched and will be released for AR 4.2.2. It's apparently hard
29
- > to backport to 4.1 unfortunately.
30
- > If you're noticing high memory usage from ActiveRecord with Apartment please upgrade.
21
+ ## Help wanted
31
22
 
32
- ```ruby
33
- gem 'rails', '4.2.1', github: 'influitive/rails', tag: 'v4.2.1.memfix'
34
- ```
23
+ We were never involved with the development of Apartment gem in the first place
24
+ and this project started out of our own needs. We will be more than happy
25
+ to collaborate to maintain the gem alive and supporting the latest versions
26
+ of ruby and rails, but your help is appreciated. Either by reporting bugs you
27
+ may find or proposing improvements to the gem itself. Feel free to reach out.
35
28
 
36
29
  ## Installation
37
30
 
@@ -40,7 +33,7 @@ gem 'rails', '4.2.1', github: 'influitive/rails', tag: 'v4.2.1.memfix'
40
33
  Add the following to your Gemfile:
41
34
 
42
35
  ```ruby
43
- gem 'apartment'
36
+ gem 'ros-apartment', require: 'apartment'
44
37
  ```
45
38
 
46
39
  Then generate your `Apartment` config file using
@@ -236,7 +229,7 @@ A Generic Elevator exists that allows you to pass a `Proc` (or anything that res
236
229
  module MyApplication
237
230
  class Application < Rails::Application
238
231
  # Obviously not a contrived example
239
- config.middleware.use Apartment::Elevators::Generic, Proc.new { |request| request.host.reverse }
232
+ config.middleware.use Apartment::Elevators::Generic, proc { |request| request.host.reverse }
240
233
  end
241
234
  end
242
235
  ```
@@ -296,6 +289,27 @@ Apartment::Tenant.drop('tenant_name')
296
289
 
297
290
  When method is called, the schema is dropped and all data from itself will be lost. Be careful with this method.
298
291
 
292
+ ### Custom Prompt
293
+
294
+ #### Console methods
295
+
296
+ `ros-apartment` console configures two helper methods:
297
+ 1. `tenant_list` - list available tenants while using the console
298
+ 2. `st(tenant_name:String)` - Switches the context to the tenant name passed, if
299
+ it exists.
300
+
301
+ #### Custom printed prompt
302
+
303
+ `ros-apartment` also has a custom prompt that gives a bit more information about
304
+ the context in which you're running. It shows the environment as well as the tenant
305
+ that is currently switched to. In order for you to enable this, you need to require
306
+ the custom console in your application.
307
+
308
+ In `application.rb` add `require 'apartment/custom_console'`.
309
+ Please note that we rely on `pry-rails` to edit the prompt, thus your project needs
310
+ to install it as well. In order to do so, you need to add `gem 'pry-rails'` to your
311
+ project's gemfile.
312
+
299
313
  ## Config
300
314
 
301
315
  The following config options should be set up in a Rails initializer such as:
@@ -310,6 +324,20 @@ Apartment.configure do |config|
310
324
  end
311
325
  ```
312
326
 
327
+ ### Skip tenant schema check
328
+
329
+ This is configurable by setting: `tenant_presence_check`. It defaults to true
330
+ in order to maintain the original gem behavior. This is only checked when using one of the PostgreSQL adapters.
331
+ The original gem behavior, when running `switch` would look for the existence of the schema before switching. This adds an extra query on every context switch. While in the default simple scenarios this is a valid check, in high volume platforms this adds some unnecessary overhead which can be detected in some other ways on the application level.
332
+
333
+ Setting this configuration value to `false` will disable the schema presence check before trying to switch the context.
334
+
335
+ ```ruby
336
+ Apartment.configure do |config|
337
+ tenant_presence_check = false
338
+ end
339
+ ```
340
+
313
341
  ### Excluding models
314
342
 
315
343
  If you have some models that should always access the 'public' tenant, you can specify this by configuring Apartment using `Apartment.configure`. This will yield a config object for you. You can set excluded models like so:
@@ -327,7 +355,20 @@ Rails will always access the 'public' tenant when accessing these models, but no
327
355
 
328
356
  ### Postgresql Schemas
329
357
 
330
- ## Providing a Different default_schema
358
+ #### Alternative: Creating new schemas by using raw SQL dumps
359
+
360
+ Apartment can be forced to use raw SQL dumps insted of `schema.rb` for creating new schemas. Use this when you are using some extra features in postgres that can't be represented in `schema.rb`, like materialized views etc.
361
+
362
+ This only applies while using postgres adapter and `config.use_schemas` is set to `true`.
363
+ (Note: this option doesn't use `db/structure.sql`, it creates SQL dump by executing `pg_dump`)
364
+
365
+ Enable this option with:
366
+
367
+ ```ruby
368
+ config.use_sql = true
369
+ ```
370
+
371
+ ### Providing a Different default_schema
331
372
 
332
373
  By default, ActiveRecord will use `"$user", public` as the default `schema_search_path`. This can be modified if you wish to use a different default schema be setting:
333
374
 
@@ -337,7 +378,7 @@ config.default_schema = "some_other_schema"
337
378
 
338
379
  With that set, all excluded models will use this schema as the table name prefix instead of `public` and `reset` on `Apartment::Tenant` will return to this schema as well.
339
380
 
340
- ## Persistent Schemas
381
+ ### Persistent Schemas
341
382
 
342
383
  Apartment will normally just switch the `schema_search_path` whole hog to the one passed in. This can lead to problems if you want other schemas to always be searched as well. Enter `persistent_schemas`. You can configure a list of other schemas that will always remain in the search path, while the default gets swapped out:
343
384
 
@@ -443,18 +484,6 @@ schema in the `search_path` at all times. We won't be able to do this though unt
443
484
  also contain the tenanted tables, which is an open issue with no real milestone to be completed.
444
485
  Happy to accept PR's on the matter.
445
486
 
446
- #### Alternative: Creating new schemas by using raw SQL dumps
447
-
448
- Apartment can be forced to use raw SQL dumps insted of `schema.rb` for creating new schemas. Use this when you are using some extra features in postgres that can't be represented in `schema.rb`, like materialized views etc.
449
-
450
- This only applies while using postgres adapter and `config.use_schemas` is set to `true`.
451
- (Note: this option doesn't use `db/structure.sql`, it creates SQL dump by executing `pg_dump`)
452
-
453
- Enable this option with:
454
- ```ruby
455
- config.use_sql = true
456
- ```
457
-
458
487
  ### Managing Migrations
459
488
 
460
489
  In order to migrate all of your tenants (or postgresql schemas) you need to provide a list
@@ -533,7 +562,12 @@ end
533
562
 
534
563
  ## Background workers
535
564
 
536
- See [apartment-sidekiq](https://github.com/influitive/apartment-sidekiq) or [apartment-activejob](https://github.com/influitive/apartment-activejob).
565
+ Both these gems have been forked as a side consequence of having a new gem name.
566
+ You can use them exactly as you were using before. They are, just like this one
567
+ a drop-in replacement.
568
+
569
+ See [apartment-sidekiq](https://github.com/rails-on-services/apartment-sidekiq)
570
+ or [apartment-activejob](https://github.com/rails-on-services/apartment-activejob).
537
571
 
538
572
  ## Callbacks
539
573
 
@@ -571,6 +605,13 @@ end
571
605
 
572
606
  * If you're looking to help, check out the TODO file for some upcoming changes I'd like to implement in Apartment.
573
607
 
608
+ ### Running bundle install
609
+
610
+ mysql2 gem in some cases fails to install.
611
+ If you face problems running bundle install in OSX, try installing the gem running:
612
+
613
+ `gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include`
614
+
574
615
  ## License
575
616
 
576
617
  Apartment is released under the [MIT License](http://www.opensource.org/licenses/MIT).