ros-apartment 2.6.0 → 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.
- checksums.yaml +4 -4
- data/apartment.gemspec +0 -1
- data/lib/apartment/adapters/abstract_adapter.rb +6 -0
- data/lib/apartment/adapters/postgresql_adapter.rb +20 -0
- data/lib/apartment/custom_console.rb +2 -0
- data/lib/apartment/railtie.rb +17 -15
- data/lib/apartment/tasks/enhancements.rb +1 -1
- data/lib/apartment/tenant.rb +14 -5
- data/lib/apartment/version.rb +1 -1
- data/lib/tasks/apartment.rake +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e57016e050d57190e3baa0693ccd7e2e094db1cdb864f9c75e193ce06fcdddbb
|
4
|
+
data.tar.gz: 65b587e5c59e03e957e42c8ca0c0cf4d078859e078eebdcda4594e69284c3175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ebfaf0a5e4da01bceed2f3cec330aefec6bbfdb5e98dd706ec7b0305cb8bc820e58106ebb60854fc7f5d8735c02d426c87a17a9f16c4b12f34104059644419
|
7
|
+
data.tar.gz: 1a72b322cf5913313aedfb1f84d3117c5cbbd5ba36a7b62ab1cf10d2e3987d8eca8b465cfc38538b86482a08fd8412e43e1d39708d3a952e4fad8c946b0b0203
|
data/apartment.gemspec
CHANGED
@@ -46,7 +46,6 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
|
47
47
|
s.add_development_dependency 'jdbc-mysql'
|
48
48
|
s.add_development_dependency 'jdbc-postgres'
|
49
|
-
s.add_development_dependency 'jruby-openssl'
|
50
49
|
else
|
51
50
|
s.add_development_dependency 'mysql2', '~> 0.5'
|
52
51
|
s.add_development_dependency 'pg', '~> 1.2'
|
@@ -37,6 +37,12 @@ module Apartment
|
|
37
37
|
def reset
|
38
38
|
@current = default_tenant
|
39
39
|
Apartment.connection.schema_search_path = full_search_path
|
40
|
+
reset_sequence_names
|
41
|
+
end
|
42
|
+
|
43
|
+
def init
|
44
|
+
super
|
45
|
+
Apartment.connection.schema_search_path = full_search_path
|
40
46
|
end
|
41
47
|
|
42
48
|
def current
|
@@ -73,6 +79,7 @@ module Apartment
|
|
73
79
|
# there is a issue for prepared statement with changing search_path.
|
74
80
|
# https://www.postgresql.org/docs/9.3/static/sql-prepare.html
|
75
81
|
Apartment.connection.clear_cache! if postgresql_version < 90_300
|
82
|
+
reset_sequence_names
|
76
83
|
rescue *rescuable_exceptions
|
77
84
|
raise TenantNotFound, "One of the following schema(s) is invalid: \"#{tenant}\" #{full_search_path}"
|
78
85
|
end
|
@@ -104,6 +111,19 @@ module Apartment
|
|
104
111
|
# public from Rails 5.0.
|
105
112
|
Apartment.connection.send(:postgresql_version)
|
106
113
|
end
|
114
|
+
|
115
|
+
def reset_sequence_names
|
116
|
+
# sequence_name contains the schema, so it must be reset after switch
|
117
|
+
# There is `reset_sequence_name`, but that method actually goes to the database
|
118
|
+
# to find out the new name. Therefore, we do this hack to only unset the name,
|
119
|
+
# and it will be dynamically found the next time it is needed
|
120
|
+
ActiveRecord::Base.descendants
|
121
|
+
.select { |c| c.instance_variable_defined?(:@sequence_name) }
|
122
|
+
.reject { |c| c.instance_variable_defined?(:@explicit_sequence_name) && c.instance_variable_get(:@explicit_sequence_name) }
|
123
|
+
.each do |c|
|
124
|
+
c.remove_instance_variable :@sequence_name
|
125
|
+
end
|
126
|
+
end
|
107
127
|
end
|
108
128
|
|
109
129
|
# Another Adapter for Postgresql when using schemas and SQL
|
data/lib/apartment/railtie.rb
CHANGED
@@ -24,26 +24,28 @@ module Apartment
|
|
24
24
|
ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
28
|
-
# Note that this doens't entirely work as expected in Development, because this is called before classes are reloaded
|
29
|
-
# See the middleware/console declarations below to help with this. Hope to fix that soon.
|
30
|
-
#
|
27
|
+
# Make sure Apartment is reconfigured when the code is reloaded
|
31
28
|
config.to_prepare do
|
32
|
-
|
33
|
-
|
29
|
+
Apartment::Tenant.reinitialize
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
'Failed to initialize Apartment because a database connection could not be established.'
|
32
|
+
#
|
33
|
+
# Ensure that Apartment::Tenant.init is called when
|
34
|
+
# a new connection is requested.
|
35
|
+
#
|
36
|
+
module ApartmentInitializer
|
37
|
+
def connection
|
38
|
+
super.tap do
|
39
|
+
Apartment::Tenant.init_once
|
44
40
|
end
|
45
41
|
end
|
42
|
+
|
43
|
+
def arel_table
|
44
|
+
Apartment::Tenant.init_once
|
45
|
+
super
|
46
|
+
end
|
46
47
|
end
|
48
|
+
ActiveRecord::Base.singleton_class.prepend ApartmentInitializer
|
47
49
|
|
48
50
|
#
|
49
51
|
# Ensure rake tasks are loaded
|
@@ -7,7 +7,7 @@ module Apartment
|
|
7
7
|
class RakeTaskEnhancer
|
8
8
|
module TASKS
|
9
9
|
ENHANCE_BEFORE = %w[db:drop].freeze
|
10
|
-
ENHANCE_AFTER = %w[db:migrate db:rollback db:migrate:up db:migrate:down db:migrate:redo db:seed].freeze
|
10
|
+
ENHANCE_AFTER = %w[db:create db:migrate db:rollback db:migrate:up db:migrate:down db:migrate:redo db:seed].freeze
|
11
11
|
freeze
|
12
12
|
end
|
13
13
|
|
data/lib/apartment/tenant.rb
CHANGED
@@ -10,15 +10,23 @@ module Apartment
|
|
10
10
|
extend Forwardable
|
11
11
|
|
12
12
|
def_delegators :adapter, :create, :drop, :switch, :switch!, :current, :each,
|
13
|
-
:reset, :set_callback, :seed, :current_tenant,
|
13
|
+
:reset, :init, :set_callback, :seed, :current_tenant,
|
14
14
|
:default_tenant, :environmentify
|
15
15
|
|
16
16
|
attr_writer :config
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def init_once
|
19
|
+
return if @already_initialized
|
20
|
+
|
21
|
+
# To avoid infinite loops in work init is doing,
|
22
|
+
# we need to set @already_initialized to true
|
23
|
+
# before init is called
|
24
|
+
@already_initialized = true
|
25
|
+
init
|
26
|
+
end
|
27
|
+
|
28
|
+
def reinitialize
|
29
|
+
@already_initialized = false
|
22
30
|
end
|
23
31
|
|
24
32
|
# Fetch the proper multi-tenant adapter based on Rails config
|
@@ -53,6 +61,7 @@ module Apartment
|
|
53
61
|
#
|
54
62
|
def reload!(config = nil)
|
55
63
|
Thread.current[:apartment_adapter] = nil
|
64
|
+
reinitialize
|
56
65
|
@config = config
|
57
66
|
end
|
58
67
|
|
data/lib/apartment/version.rb
CHANGED
data/lib/tasks/apartment.rake
CHANGED
@@ -121,11 +121,15 @@ apartment_namespace = namespace :apartment do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def each_tenant(&block)
|
124
|
-
Parallel.each(
|
124
|
+
Parallel.each(tenants_without_default, in_threads: Apartment.parallel_migration_threads) do |tenant|
|
125
125
|
block.call(tenant)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
def tenants_without_default
|
130
|
+
tenants - [Apartment.default_schema]
|
131
|
+
end
|
132
|
+
|
129
133
|
def tenants
|
130
134
|
ENV['DB'] ? ENV['DB'].split(',').map(&:strip) : Apartment.tenant_names || []
|
131
135
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ros-apartment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-06-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|