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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.pryrc +5 -3
  3. data/.rubocop.yml +22 -0
  4. data/.rubocop_todo.yml +29 -0
  5. data/.story_branch.yml +5 -0
  6. data/.travis.yml +20 -36
  7. data/Appraisals +16 -29
  8. data/Gemfile +5 -2
  9. data/Guardfile +3 -1
  10. data/HISTORY.md +57 -0
  11. data/README.md +64 -21
  12. data/Rakefile +36 -22
  13. data/TODO.md +0 -1
  14. data/apartment.gemspec +17 -10
  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 +38 -14
  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/log_subscriber.rb +41 -0
  25. data/lib/apartment/active_record/schema_migration.rb +13 -0
  26. data/lib/apartment/adapters/abstract_adapter.rb +49 -45
  27. data/lib/apartment/adapters/abstract_jdbc_adapter.rb +4 -3
  28. data/lib/apartment/adapters/jdbc_mysql_adapter.rb +3 -3
  29. data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +20 -13
  30. data/lib/apartment/adapters/mysql2_adapter.rb +12 -9
  31. data/lib/apartment/adapters/postgis_adapter.rb +3 -2
  32. data/lib/apartment/adapters/postgresql_adapter.rb +59 -27
  33. data/lib/apartment/adapters/sqlite3_adapter.rb +18 -8
  34. data/lib/apartment/console.rb +35 -3
  35. data/lib/apartment/custom_console.rb +42 -0
  36. data/lib/apartment/deprecation.rb +2 -1
  37. data/lib/apartment/elevators/domain.rb +4 -3
  38. data/lib/apartment/elevators/first_subdomain.rb +3 -2
  39. data/lib/apartment/elevators/generic.rb +4 -3
  40. data/lib/apartment/elevators/host.rb +6 -1
  41. data/lib/apartment/elevators/host_hash.rb +6 -2
  42. data/lib/apartment/elevators/subdomain.rb +9 -5
  43. data/lib/apartment/migrator.rb +4 -3
  44. data/lib/apartment/model.rb +27 -0
  45. data/lib/apartment/railtie.rb +27 -15
  46. data/lib/apartment/reloader.rb +2 -1
  47. data/lib/apartment/tasks/enhancements.rb +4 -6
  48. data/lib/apartment/tasks/task_helper.rb +35 -0
  49. data/lib/apartment/tenant.rb +19 -9
  50. data/lib/apartment/version.rb +3 -1
  51. data/lib/generators/apartment/install/install_generator.rb +4 -3
  52. data/lib/generators/apartment/install/templates/apartment.rb +8 -2
  53. data/lib/tasks/apartment.rake +22 -44
  54. metadata +51 -230
  55. data/spec/adapters/jdbc_mysql_adapter_spec.rb +0 -19
  56. data/spec/adapters/jdbc_postgresql_adapter_spec.rb +0 -41
  57. data/spec/adapters/mysql2_adapter_spec.rb +0 -59
  58. data/spec/adapters/postgresql_adapter_spec.rb +0 -61
  59. data/spec/adapters/sqlite3_adapter_spec.rb +0 -83
  60. data/spec/apartment_spec.rb +0 -11
  61. data/spec/config/database.yml.sample +0 -49
  62. data/spec/dummy/Rakefile +0 -7
  63. data/spec/dummy/app/controllers/application_controller.rb +0 -6
  64. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  65. data/spec/dummy/app/models/company.rb +0 -3
  66. data/spec/dummy/app/models/user.rb +0 -3
  67. data/spec/dummy/app/views/application/index.html.erb +0 -1
  68. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  69. data/spec/dummy/config.ru +0 -4
  70. data/spec/dummy/config/application.rb +0 -49
  71. data/spec/dummy/config/boot.rb +0 -11
  72. data/spec/dummy/config/database.yml.sample +0 -44
  73. data/spec/dummy/config/environment.rb +0 -5
  74. data/spec/dummy/config/environments/development.rb +0 -28
  75. data/spec/dummy/config/environments/production.rb +0 -51
  76. data/spec/dummy/config/environments/test.rb +0 -34
  77. data/spec/dummy/config/initializers/apartment.rb +0 -4
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  79. data/spec/dummy/config/initializers/inflections.rb +0 -10
  80. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  81. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  82. data/spec/dummy/config/initializers/session_store.rb +0 -8
  83. data/spec/dummy/config/locales/en.yml +0 -5
  84. data/spec/dummy/config/routes.rb +0 -3
  85. data/spec/dummy/db/migrate/20110613152810_create_dummy_models.rb +0 -39
  86. data/spec/dummy/db/migrate/20111202022214_create_table_books.rb +0 -14
  87. data/spec/dummy/db/migrate/20180415260934_create_public_tokens.rb +0 -13
  88. data/spec/dummy/db/schema.rb +0 -55
  89. data/spec/dummy/db/seeds.rb +0 -5
  90. data/spec/dummy/db/seeds/import.rb +0 -5
  91. data/spec/dummy/public/404.html +0 -26
  92. data/spec/dummy/public/422.html +0 -26
  93. data/spec/dummy/public/500.html +0 -26
  94. data/spec/dummy/public/favicon.ico +0 -0
  95. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  96. data/spec/dummy/script/rails +0 -6
  97. data/spec/dummy_engine/.gitignore +0 -8
  98. data/spec/dummy_engine/Gemfile +0 -15
  99. data/spec/dummy_engine/Rakefile +0 -34
  100. data/spec/dummy_engine/bin/rails +0 -12
  101. data/spec/dummy_engine/config/initializers/apartment.rb +0 -51
  102. data/spec/dummy_engine/dummy_engine.gemspec +0 -24
  103. data/spec/dummy_engine/lib/dummy_engine.rb +0 -4
  104. data/spec/dummy_engine/lib/dummy_engine/engine.rb +0 -4
  105. data/spec/dummy_engine/lib/dummy_engine/version.rb +0 -3
  106. data/spec/dummy_engine/test/dummy/Rakefile +0 -6
  107. data/spec/dummy_engine/test/dummy/config.ru +0 -4
  108. data/spec/dummy_engine/test/dummy/config/application.rb +0 -22
  109. data/spec/dummy_engine/test/dummy/config/boot.rb +0 -5
  110. data/spec/dummy_engine/test/dummy/config/database.yml +0 -25
  111. data/spec/dummy_engine/test/dummy/config/environment.rb +0 -5
  112. data/spec/dummy_engine/test/dummy/config/environments/development.rb +0 -37
  113. data/spec/dummy_engine/test/dummy/config/environments/production.rb +0 -78
  114. data/spec/dummy_engine/test/dummy/config/environments/test.rb +0 -39
  115. data/spec/dummy_engine/test/dummy/config/initializers/assets.rb +0 -8
  116. data/spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  117. data/spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  118. data/spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  119. data/spec/dummy_engine/test/dummy/config/initializers/inflections.rb +0 -16
  120. data/spec/dummy_engine/test/dummy/config/initializers/mime_types.rb +0 -4
  121. data/spec/dummy_engine/test/dummy/config/initializers/session_store.rb +0 -3
  122. data/spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  123. data/spec/dummy_engine/test/dummy/config/locales/en.yml +0 -23
  124. data/spec/dummy_engine/test/dummy/config/routes.rb +0 -56
  125. data/spec/dummy_engine/test/dummy/config/secrets.yml +0 -22
  126. data/spec/examples/connection_adapter_examples.rb +0 -42
  127. data/spec/examples/generic_adapter_custom_configuration_example.rb +0 -95
  128. data/spec/examples/generic_adapter_examples.rb +0 -163
  129. data/spec/examples/schema_adapter_examples.rb +0 -234
  130. data/spec/integration/apartment_rake_integration_spec.rb +0 -107
  131. data/spec/integration/query_caching_spec.rb +0 -81
  132. data/spec/integration/use_within_an_engine_spec.rb +0 -28
  133. data/spec/schemas/v1.rb +0 -16
  134. data/spec/schemas/v2.rb +0 -43
  135. data/spec/schemas/v3.rb +0 -49
  136. data/spec/spec_helper.rb +0 -61
  137. data/spec/support/apartment_helpers.rb +0 -43
  138. data/spec/support/capybara_sessions.rb +0 -15
  139. data/spec/support/config.rb +0 -10
  140. data/spec/support/contexts.rb +0 -52
  141. data/spec/support/requirements.rb +0 -35
  142. data/spec/support/setup.rb +0 -46
  143. data/spec/tasks/apartment_rake_spec.rb +0 -129
  144. data/spec/tenant_spec.rb +0 -190
  145. data/spec/unit/config_spec.rb +0 -112
  146. data/spec/unit/elevators/domain_spec.rb +0 -32
  147. data/spec/unit/elevators/first_subdomain_spec.rb +0 -24
  148. data/spec/unit/elevators/generic_spec.rb +0 -54
  149. data/spec/unit/elevators/host_hash_spec.rb +0 -32
  150. data/spec/unit/elevators/host_spec.rb +0 -89
  151. data/spec/unit/elevators/subdomain_spec.rb +0 -76
  152. data/spec/unit/migrator_spec.rb +0 -77
  153. data/spec/unit/reloader_spec.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea7b5564bca9125cfb7b8a7863793c69a3462dabd8211d274891b79a948c28f5
4
- data.tar.gz: c502a0c3dccdd4edca005b68b6e945d82a6943716d917ef2df2e6fa91d2a2204
3
+ metadata.gz: 7c5ea61531091303bdf3ab60326eadb7ffda6ea92b03079fd8a93583067037c7
4
+ data.tar.gz: 95c482e8304a914d6098f1f4ea498f93e1a4827d851e4ea4a283f18ca51079ae
5
5
  SHA512:
6
- metadata.gz: c1babac9d50b907b36337157870ab606291a91cb022a80b11a1e3f008301f2a1b019137fb8ea03119e2a054b97041d4e532191142fff97eee3ad27cc30b10a0c
7
- data.tar.gz: 7cee77bbe095d7f2d8b3a64468b5730d719152d5ec904ab15261b49366bc113dbb97f7b4a1297535c4c294d8b8099090f542ae315a2744fe55d1fb19895b4615
6
+ metadata.gz: '09f36cbd0d164f3f692aaf9b2a60b55aa5289537b07c299e49d651a1f1fe6aba6a8d67578076ccad94c2ad62bcaf46e74900c532664f696d1dd4ae673fb49d1d'
7
+ data.tar.gz: b38b9708487fa0e64c93d8349f922dafe2678b09020f5c5a5e77aca5acff4510254737094636d3c25a03e57e76280a20c403fe4021b6e64bcb3e9956b4a77acb
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,22 @@
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
+ - 'gemfiles/vendor/**/*'
11
+
12
+ Style/WordArray:
13
+ Exclude:
14
+ - spec/schemas/**/*.rb
15
+
16
+ Style/NumericLiterals:
17
+ Exclude:
18
+ - spec/schemas/**/*.rb
19
+
20
+ Layout/EmptyLineAfterMagicComment:
21
+ Exclude:
22
+ - 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,5 @@
1
+ ---
2
+ tracker: github
3
+ issue_placement: beginning
4
+ project_id:
5
+ - rails-on-services/apartment
@@ -4,62 +4,46 @@ 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'
32
+
30
33
  env:
31
34
  RUBY_GC_MALLOC_LIMIT: 90000000
32
35
  RUBY_GC_HEAP_FREE_SLOTS: 200000
33
36
  jobs:
37
+ include:
38
+ - name: Rubocop Lint
39
+ script: gem install perx-rubocop && rubocop
40
+
34
41
  allow_failures:
35
42
  - rvm: ruby-head
43
+ - rvm: jruby-head
36
44
  - gemfile: gemfiles/rails_master.gemfile
37
- - rvm: jruby-9.1.17.0
38
- gemfile: gemfiles/rails_5_0.gemfile
39
45
  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
46
+ - rvm: 2.4.10
61
47
  gemfile: gemfiles/rails_6_0.gemfile
62
- - rvm: jruby-9.1.17.0
63
- gemfile: gemfiles/rails_master.gemfile
64
48
  fast_finish: true
65
49
  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
- source 'http://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://my.diffend.io/protect/gems'
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,60 @@
1
+ # 2.6.1
2
+
3
+ ## Enhancements
4
+ - N/a
5
+
6
+ ## Bugfixes
7
+ - [Resolves influitive#607] Avoid early connection
8
+ - <https://github.com/rails-on-services/apartment/pull/39>
9
+ - <https://github.com/rails-on-services/apartment/pull/53>
10
+ - <https://github.com/rails-on-services/apartment/pull/51>
11
+ - [Resolves #52] Rake db:setup tries to seed non existent tenant - <https://github.com/rails-on-services/apartment/pull/54>
12
+ - [Resolves #56] DB rollback uses second last migration - <https://github.com/rails-on-services/apartment/pull/57>
13
+
14
+ ## Chores
15
+ - N/a
16
+
17
+ # 2.6.0
18
+
19
+ ## Enhancements
20
+ - [Resolves #26] Support configuration for skip checking of schema existence before switching
21
+ - [Resolves #41] Add tenant info to console boot
22
+
23
+ ## Bugfixes
24
+ - [Resolves #37] Custom Console deprecation warning
25
+ - [Resolves #42] After switch callback not working with nil argument
26
+
27
+ ## Chores
28
+ - Updated github actions configuration to run on PRs as well
29
+
30
+ # 2.5.0
31
+
32
+ ## Enhancements
33
+ - [Resolves #6] Adds support for rails 6.1
34
+ - [Resolves #27] Adds support to not rely on set search path, but instead prepends the schema name to the table name when using postgresql with schemas.
35
+ - [Resolves #35] Cache keys are now tenant dependent
36
+
37
+ ## Bugfixes
38
+ - [Resolves #27] Manually switching connection between read and write forgets the schema
39
+
40
+ ## Chores
41
+ - [Resolves #31] Add latest ruby versions to test matrix
42
+
43
+ # 2.4.0
44
+
45
+ ## Enhancements
46
+ - [Resolves #14] Add console info about tenants and fast switches #17
47
+ - Skip init if we're running webpacker:compile #18
48
+
49
+ ## Bugfixes
50
+ - Don't crash when no database connection is present #16
51
+ - Rescuing ActiveRecord::NoDatabaseError when dropping tenants #19
52
+
53
+ ## Chores
54
+ - Rakefile should use mysql port from configuration #5
55
+ - [Resolves #9] Cleanup rubocop todo #8
56
+ - Cleanup travis matrix #23
57
+
1
58
  # 2.3.0
2
59
  * January 3, 2020
3
60
 
data/README.md CHANGED
@@ -1,8 +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)
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)
6
6
 
7
7
  *Multitenancy for Rails and ActiveRecord*
8
8
 
@@ -33,7 +33,7 @@ may find or proposing improvements to the gem itself. Feel free to reach out.
33
33
  Add the following to your Gemfile:
34
34
 
35
35
  ```ruby
36
- gem 'ros-apartment'
36
+ gem 'ros-apartment', require: 'apartment'
37
37
  ```
38
38
 
39
39
  Then generate your `Apartment` config file using
@@ -229,7 +229,7 @@ A Generic Elevator exists that allows you to pass a `Proc` (or anything that res
229
229
  module MyApplication
230
230
  class Application < Rails::Application
231
231
  # Obviously not a contrived example
232
- config.middleware.use Apartment::Elevators::Generic, Proc.new { |request| request.host.reverse }
232
+ config.middleware.use Apartment::Elevators::Generic, proc { |request| request.host.reverse }
233
233
  end
234
234
  end
235
235
  ```
@@ -289,6 +289,27 @@ Apartment::Tenant.drop('tenant_name')
289
289
 
290
290
  When method is called, the schema is dropped and all data from itself will be lost. Be careful with this method.
291
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
+
292
313
  ## Config
293
314
 
294
315
  The following config options should be set up in a Rails initializer such as:
@@ -303,6 +324,20 @@ Apartment.configure do |config|
303
324
  end
304
325
  ```
305
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
+
306
341
  ### Excluding models
307
342
 
308
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:
@@ -320,17 +355,30 @@ Rails will always access the 'public' tenant when accessing these models, but no
320
355
 
321
356
  ### Postgresql Schemas
322
357
 
323
- ## 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_tenant
324
372
 
325
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:
326
374
 
327
375
  ```ruby
328
- config.default_schema = "some_other_schema"
376
+ config.default_tenant = "some_other_schema"
329
377
  ```
330
378
 
331
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.
332
380
 
333
- ## Persistent Schemas
381
+ ### Persistent Schemas
334
382
 
335
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:
336
384
 
@@ -398,7 +446,7 @@ schema_search_path: "public,shared_extensions"
398
446
  ...
399
447
  ```
400
448
 
401
- This would be for a config with `default_schema` set to `public` and `persistent_schemas` set to `['shared_extensions']`. **Note**: This only works on Heroku with [Rails 4.1+](https://devcenter.heroku.com/changelog-items/426). For apps that use older Rails versions hosted on Heroku, the only way to properly setup is to start with a fresh PostgreSQL instance:
449
+ This would be for a config with `default_tenant` set to `public` and `persistent_schemas` set to `['shared_extensions']`. **Note**: This only works on Heroku with [Rails 4.1+](https://devcenter.heroku.com/changelog-items/426). For apps that use older Rails versions hosted on Heroku, the only way to properly setup is to start with a fresh PostgreSQL instance:
402
450
 
403
451
  1. Append `?schema_search_path=public,hstore` to your `DATABASE_URL` environment variable, by this you don't have to revise the `database.yml` file (which is impossible since Heroku regenerates a completely different and immutable `database.yml` of its own on each deploy)
404
452
  2. Run `heroku pg:psql` from your command line
@@ -436,18 +484,6 @@ schema in the `search_path` at all times. We won't be able to do this though unt
436
484
  also contain the tenanted tables, which is an open issue with no real milestone to be completed.
437
485
  Happy to accept PR's on the matter.
438
486
 
439
- #### Alternative: Creating new schemas by using raw SQL dumps
440
-
441
- 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.
442
-
443
- This only applies while using postgres adapter and `config.use_schemas` is set to `true`.
444
- (Note: this option doesn't use `db/structure.sql`, it creates SQL dump by executing `pg_dump`)
445
-
446
- Enable this option with:
447
- ```ruby
448
- config.use_sql = true
449
- ```
450
-
451
487
  ### Managing Migrations
452
488
 
453
489
  In order to migrate all of your tenants (or postgresql schemas) you need to provide a list
@@ -569,6 +605,13 @@ end
569
605
 
570
606
  * If you're looking to help, check out the TODO file for some upcoming changes I'd like to implement in Apartment.
571
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
+
572
615
  ## License
573
616
 
574
617
  Apartment is released under the [MIT License](http://www.opensource.org/licenses/MIT).