ros-apartment 2.5.0 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/changelog.yml +41 -0
  3. data/.rubocop.yml +74 -4
  4. data/.rubocop_todo.yml +50 -13
  5. data/.story_branch.yml +1 -0
  6. data/.travis.yml +5 -0
  7. data/CHANGELOG.md +917 -0
  8. data/Gemfile +1 -1
  9. data/Guardfile +0 -15
  10. data/HISTORY.md +159 -68
  11. data/README.md +17 -3
  12. data/Rakefile +4 -2
  13. data/TODO.md +0 -1
  14. data/gemfiles/rails_5_0.gemfile +1 -1
  15. data/gemfiles/rails_5_1.gemfile +1 -1
  16. data/gemfiles/rails_5_2.gemfile +1 -1
  17. data/gemfiles/rails_6_0.gemfile +1 -1
  18. data/gemfiles/rails_master.gemfile +1 -1
  19. data/lib/apartment.rb +13 -12
  20. data/lib/apartment/active_record/connection_handling.rb +3 -0
  21. data/lib/apartment/active_record/internal_metadata.rb +0 -2
  22. data/lib/apartment/active_record/log_subscriber.rb +44 -0
  23. data/lib/apartment/active_record/schema_migration.rb +0 -2
  24. data/lib/apartment/adapters/abstract_adapter.rb +17 -14
  25. data/lib/apartment/adapters/abstract_jdbc_adapter.rb +2 -1
  26. data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +11 -5
  27. data/lib/apartment/adapters/mysql2_adapter.rb +5 -0
  28. data/lib/apartment/adapters/postgresql_adapter.rb +40 -4
  29. data/lib/apartment/adapters/sqlite3_adapter.rb +2 -0
  30. data/lib/apartment/console.rb +7 -6
  31. data/lib/apartment/custom_console.rb +25 -9
  32. data/lib/apartment/railtie.rb +19 -15
  33. data/lib/apartment/tasks/task_helper.rb +33 -0
  34. data/lib/apartment/tenant.rb +17 -6
  35. data/lib/apartment/version.rb +1 -1
  36. data/lib/generators/apartment/install/templates/apartment.rb +7 -1
  37. data/lib/tasks/apartment.rake +16 -37
  38. data/{apartment.gemspec → ros-apartment.gemspec} +1 -3
  39. metadata +13 -10
  40. data/.github/workflows/.rubocop-linter.yml +0 -22
data/README.md CHANGED
@@ -324,6 +324,20 @@ Apartment.configure do |config|
324
324
  end
325
325
  ```
326
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
+
327
341
  ### Excluding models
328
342
 
329
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:
@@ -354,12 +368,12 @@ Enable this option with:
354
368
  config.use_sql = true
355
369
  ```
356
370
 
357
- ### Providing a Different default_schema
371
+ ### Providing a Different default_tenant
358
372
 
359
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:
360
374
 
361
375
  ```ruby
362
- config.default_schema = "some_other_schema"
376
+ config.default_tenant = "some_other_schema"
363
377
  ```
364
378
 
365
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.
@@ -432,7 +446,7 @@ schema_search_path: "public,shared_extensions"
432
446
  ...
433
447
  ```
434
448
 
435
- 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:
436
450
 
437
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)
438
452
  2. Run `heroku pg:psql` from your command line
data/Rakefile CHANGED
@@ -46,8 +46,10 @@ namespace :db do
46
46
  apartment_db_file = 'spec/config/database.yml'
47
47
  rails_db_file = 'spec/dummy/config/database.yml'
48
48
 
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)
49
+ unless File.exist?(apartment_db_file)
50
+ FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, verbose: true)
51
+ end
52
+ FileUtils.copy(rails_db_file + '.sample', rails_db_file, verbose: true) unless File.exist?(rails_db_file)
51
53
  end
52
54
  end
53
55
 
data/TODO.md CHANGED
@@ -46,6 +46,5 @@
46
46
 
47
47
  Quick TODOs
48
48
 
49
- 1. `default_tenant` should be up to the adapter, not the Apartment class, deprecate `default_schema`
50
49
  2. deprecation.rb rescues everything, we have a hard dependency on ActiveSupport so this is unnecessary
51
50
  3.
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "perx-rubocop", "~> 0.0.3"
6
5
  gem "rails", "~> 5.0.0"
6
+ gem "rubocop"
7
7
 
8
8
  group :local do
9
9
  gem "guard-rspec", "~> 4.2"
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "perx-rubocop", "~> 0.0.3"
6
5
  gem "rails", "~> 5.1.0"
6
+ gem "rubocop"
7
7
 
8
8
  group :local do
9
9
  gem "guard-rspec", "~> 4.2"
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "perx-rubocop", "~> 0.0.3"
6
5
  gem "rails", "~> 5.2.0"
6
+ gem "rubocop"
7
7
 
8
8
  group :local do
9
9
  gem "guard-rspec", "~> 4.2"
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "perx-rubocop", "~> 0.0.3"
6
5
  gem "rails", "~> 6.0.0"
6
+ gem "rubocop"
7
7
 
8
8
  group :local do
9
9
  gem "guard-rspec", "~> 4.2"
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "perx-rubocop", "~> 0.0.3"
6
5
  gem "rails", git: "https://github.com/rails/rails.git"
6
+ gem "rubocop"
7
7
 
8
8
  group :local do
9
9
  gem "guard-rspec", "~> 4.2"
@@ -6,25 +6,28 @@ require 'forwardable'
6
6
  require 'active_record'
7
7
  require 'apartment/tenant'
8
8
 
9
- # require_relative 'apartment/arel/visitors/postgresql'
9
+ require_relative 'apartment/active_record/log_subscriber'
10
10
 
11
- require_relative 'apartment/active_record/connection_handling' if ActiveRecord.version.release >= Gem::Version.new('6.0')
11
+ if ActiveRecord.version.release >= Gem::Version.new('6.0')
12
+ require_relative 'apartment/active_record/connection_handling'
13
+ end
12
14
 
13
15
  if ActiveRecord.version.release >= Gem::Version.new('6.1')
14
16
  require_relative 'apartment/active_record/schema_migration'
15
17
  require_relative 'apartment/active_record/internal_metadata'
16
18
  end
17
19
 
20
+ # Apartment main definitions
18
21
  module Apartment
19
22
  class << self
20
23
  extend Forwardable
21
24
 
22
- ACCESSOR_METHODS = %i[use_schemas use_sql seed_after_create prepend_environment
23
- append_environment with_multi_server_setup].freeze
25
+ ACCESSOR_METHODS = %i[use_schemas use_sql seed_after_create prepend_environment default_tenant
26
+ append_environment with_multi_server_setup tenant_presence_check active_record_log].freeze
24
27
 
25
28
  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
29
+ persistent_schemas connection_class
30
+ db_migrate_tenants seed_data_file
28
31
  parallel_migration_threads pg_excluded_names].freeze
29
32
 
30
33
  attr_accessor(*ACCESSOR_METHODS)
@@ -53,6 +56,10 @@ module Apartment
53
56
  extract_tenant_config
54
57
  end
55
58
 
59
+ def tld_length=(_)
60
+ Apartment::Deprecation.warn('`config.tld_length` have no effect because it was removed in https://github.com/influitive/apartment/pull/309')
61
+ end
62
+
56
63
  def db_config_for(tenant)
57
64
  (tenants_with_config[tenant] || connection_config)
58
65
  end
@@ -70,15 +77,9 @@ module Apartment
70
77
  @excluded_models || []
71
78
  end
72
79
 
73
- def default_schema
74
- @default_schema || 'public' # TODO: 'public' is postgres specific
75
- end
76
-
77
80
  def parallel_migration_threads
78
81
  @parallel_migration_threads || 0
79
82
  end
80
- alias default_tenant default_schema
81
- alias default_tenant= default_schema=
82
83
 
83
84
  def persistent_schemas
84
85
  @persistent_schemas || []
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord
4
+ # This is monkeypatching activerecord to ensure that whenever a new connection is established it
5
+ # switches to the same tenant as before the connection switching. This problem is more evident when
6
+ # using read replica in Rails 6
4
7
  module ConnectionHandling
5
8
  def connected_to_with_tenant(database: nil, role: nil, prevent_writes: false, &blk)
6
9
  current_tenant = Apartment::Tenant.current
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Rails/ApplicationRecord
4
3
  class InternalMetadata < ActiveRecord::Base # :nodoc:
5
4
  class << self
6
5
  def table_exists?
@@ -8,4 +7,3 @@ class InternalMetadata < ActiveRecord::Base # :nodoc:
8
7
  end
9
8
  end
10
9
  end
11
- # rubocop:enable Rails/ApplicationRecord
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ # Supports the logging configuration to prepend the database and schema in the ActiveRecord log
5
+ class LogSubscriber
6
+ def apartment_log
7
+ return unless Apartment.active_record_log
8
+
9
+ database = color("[#{Apartment.connection.current_database}] ", ActiveSupport::LogSubscriber::MAGENTA, true)
10
+ schema = nil
11
+ unless Apartment.connection.schema_search_path.nil?
12
+ schema = color("[#{Apartment.connection.schema_search_path.tr('"', '')}] ",
13
+ ActiveSupport::LogSubscriber::YELLOW, true)
14
+ end
15
+ "#{database}#{schema}"
16
+ end
17
+
18
+ def payload_binds(binds, type_casted_binds)
19
+ return unless (binds || []).empty?
20
+
21
+ casted_params = type_casted_binds(type_casted_binds)
22
+ ' ' + binds.zip(casted_params).map { |attr, value| render_bind(attr, value) }.inspect
23
+ end
24
+
25
+ def sql(event)
26
+ self.class.runtime += event.duration
27
+ return unless logger.debug?
28
+
29
+ payload = event.payload
30
+
31
+ return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])
32
+
33
+ name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
34
+ name = "CACHE #{name}" if payload[:cached]
35
+ sql = payload[:sql]
36
+ binds = payload_binds(payload[:binds], payload[:type_casted_binds])
37
+
38
+ name = colorize_payload_name(name, payload[:name])
39
+ sql = color(sql, sql_color(sql), true) if colorize_logging
40
+
41
+ debug " #{apartment_log}#{name} #{sql}#{binds}"
42
+ end
43
+ end
44
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord
4
- # rubocop:disable Rails/ApplicationRecord
5
4
  class SchemaMigration < ActiveRecord::Base # :nodoc:
6
5
  class << self
7
6
  def table_exists?
@@ -9,5 +8,4 @@ module ActiveRecord
9
8
  end
10
9
  end
11
10
  end
12
- # rubocop:enable Rails/ApplicationRecord
13
11
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Apartment
4
4
  module Adapters
5
- # rubocop:disable Metrics/ClassLength
5
+ # Abstract adapter from which all the Apartment DB related adapters will inherit the base logic
6
6
  class AbstractAdapter
7
7
  include ActiveSupport::Callbacks
8
8
  define_callbacks :create, :switch
@@ -35,6 +35,12 @@ module Apartment
35
35
  end
36
36
  end
37
37
 
38
+ # Initialize Apartment config options such as excluded_models
39
+ #
40
+ def init
41
+ process_excluded_models
42
+ end
43
+
38
44
  # Note alias_method here doesn't work with inheritence apparently ??
39
45
  #
40
46
  def current
@@ -48,7 +54,6 @@ module Apartment
48
54
  def default_tenant
49
55
  @default_tenant || Apartment.default_tenant
50
56
  end
51
- alias default_schema default_tenant # TODO: deprecate default_schema
52
57
 
53
58
  # Drop the tenant
54
59
  #
@@ -68,8 +73,6 @@ module Apartment
68
73
  #
69
74
  def switch!(tenant = nil)
70
75
  run_callbacks :switch do
71
- return reset if tenant.nil?
72
-
73
76
  connect_to_new(tenant).tap do
74
77
  Apartment.connection.clear_query_cache
75
78
  end
@@ -130,14 +133,12 @@ module Apartment
130
133
  # @return {String} tenant name with Rails environment *optionally* prepended
131
134
  #
132
135
  def environmentify(tenant)
133
- if !tenant.include?(Rails.env)
134
- if Apartment.prepend_environment
135
- "#{Rails.env}_#{tenant}"
136
- elsif Apartment.append_environment
137
- "#{tenant}_#{Rails.env}"
138
- else
139
- tenant
140
- end
136
+ return tenant if tenant.nil? || tenant.include?(Rails.env)
137
+
138
+ if Apartment.prepend_environment
139
+ "#{Rails.env}_#{tenant}"
140
+ elsif Apartment.append_environment
141
+ "#{tenant}_#{Rails.env}"
141
142
  else
142
143
  tenant
143
144
  end
@@ -175,6 +176,8 @@ module Apartment
175
176
  # @param {String} tenant Database name
176
177
  #
177
178
  def connect_to_new(tenant)
179
+ return reset if tenant.nil?
180
+
178
181
  query_cache_enabled = ActiveRecord::Base.connection.query_cache_enabled
179
182
 
180
183
  Apartment.establish_connection multi_tenantify(tenant)
@@ -237,7 +240,8 @@ module Apartment
237
240
  def with_neutral_connection(tenant, &_block)
238
241
  if Apartment.with_multi_server_setup
239
242
  # neutral connection is necessary whenever you need to create/remove a database from a server.
240
- # example: when you use postgresql, you need to connect to the default postgresql database before you create your own.
243
+ # example: when you use postgresql, you need to connect to the default postgresql database before you create
244
+ # your own.
241
245
  SeparateDbConnectionHandler.establish_connection(multi_tenantify(tenant, false))
242
246
  yield(SeparateDbConnectionHandler.connection)
243
247
  SeparateDbConnectionHandler.connection.close
@@ -266,5 +270,4 @@ module Apartment
266
270
  end
267
271
  end
268
272
  end
269
- # rubocop:enable Metrics/ClassLength
270
273
  end
@@ -4,11 +4,12 @@ require 'apartment/adapters/abstract_adapter'
4
4
 
5
5
  module Apartment
6
6
  module Adapters
7
+ # JDBC Abstract adapter
7
8
  class AbstractJDBCAdapter < AbstractAdapter
8
9
  private
9
10
 
10
11
  def multi_tenantify_with_tenant_db_name(config, tenant)
11
- config[:url] = "#{config[:url].gsub(%r{(\S+)\/.+$}, '\1')}/#{environmentify(tenant)}"
12
+ config[:url] = "#{config[:url].gsub(%r{(\S+)/.+$}, '\1')}/#{environmentify(tenant)}"
12
13
  end
13
14
 
14
15
  def rescue_from
@@ -3,6 +3,7 @@
3
3
  require 'apartment/adapters/postgresql_adapter'
4
4
 
5
5
  module Apartment
6
+ # JDBC helper to decide wether to use JDBC Postgresql Adapter or JDBC Postgresql Adapter with Schemas
6
7
  module Tenant
7
8
  def self.jdbc_postgresql_adapter(config)
8
9
  if Apartment.use_schemas
@@ -19,7 +20,7 @@ module Apartment
19
20
  private
20
21
 
21
22
  def multi_tenantify_with_tenant_db_name(config, tenant)
22
- config[:url] = "#{config[:url].gsub(%r{(\S+)\/.+$}, '\1')}/#{environmentify(tenant)}"
23
+ config[:url] = "#{config[:url].gsub(%r{(\S+)/.+$}, '\1')}/#{environmentify(tenant)}"
23
24
  end
24
25
 
25
26
  def create_tenant_command(conn, tenant)
@@ -37,12 +38,11 @@ module Apartment
37
38
  #
38
39
  def connect_to_new(tenant = nil)
39
40
  return reset if tenant.nil?
40
- # rubocop:disable Style/RaiseArgs
41
- raise ActiveRecord::StatementInvalid.new("Could not find schema #{tenant}") unless Apartment.connection.all_schemas.include? tenant.to_s
42
41
 
43
- # rubocop:enable Style/RaiseArgs
42
+ tenant = tenant.to_s
43
+ raise ActiveRecord::StatementInvalid, "Could not find schema #{tenant}" unless tenant_exists?(tenant)
44
44
 
45
- @current = tenant.to_s
45
+ @current = tenant
46
46
  Apartment.connection.schema_search_path = full_search_path
47
47
  rescue ActiveRecord::StatementInvalid, ActiveRecord::JDBCError
48
48
  raise TenantNotFound, "One of the following schema(s) is invalid: #{full_search_path}"
@@ -50,6 +50,12 @@ module Apartment
50
50
 
51
51
  private
52
52
 
53
+ def tenant_exists?(tenant)
54
+ return true unless Apartment.tenant_presence_check
55
+
56
+ Apartment.connection.all_schemas.include? tenant
57
+ end
58
+
53
59
  def rescue_from
54
60
  ActiveRecord::JDBCError
55
61
  end
@@ -3,6 +3,7 @@
3
3
  require 'apartment/adapters/abstract_adapter'
4
4
 
5
5
  module Apartment
6
+ # Helper module to decide wether to use mysql2 adapter or mysql2 adapter with schemas
6
7
  module Tenant
7
8
  def self.mysql2_adapter(config)
8
9
  if Apartment.use_schemas
@@ -14,6 +15,7 @@ module Apartment
14
15
  end
15
16
 
16
17
  module Adapters
18
+ # Mysql2 Adapter
17
19
  class Mysql2Adapter < AbstractAdapter
18
20
  def initialize(config)
19
21
  super
@@ -28,6 +30,7 @@ module Apartment
28
30
  end
29
31
  end
30
32
 
33
+ # Mysql2 Schemas Adapter
31
34
  class Mysql2SchemaAdapter < AbstractAdapter
32
35
  def initialize(config)
33
36
  super
@@ -39,6 +42,8 @@ module Apartment
39
42
  # Reset current tenant to the default_tenant
40
43
  #
41
44
  def reset
45
+ return unless default_tenant
46
+
42
47
  Apartment.connection.execute "use `#{default_tenant}`"
43
48
  end
44
49
 
@@ -30,6 +30,10 @@ module Apartment
30
30
  reset
31
31
  end
32
32
 
33
+ def default_tenant
34
+ @default_tenant = Apartment.default_tenant || 'public'
35
+ end
36
+
33
37
  # Reset schema search path to the default schema_search_path
34
38
  #
35
39
  # @return {String} default schema search path
@@ -37,6 +41,12 @@ module Apartment
37
41
  def reset
38
42
  @current = default_tenant
39
43
  Apartment.connection.schema_search_path = full_search_path
44
+ reset_sequence_names
45
+ end
46
+
47
+ def init
48
+ super
49
+ Apartment.connection.schema_search_path = full_search_path
40
50
  end
41
51
 
42
52
  def current
@@ -62,24 +72,30 @@ module Apartment
62
72
  #
63
73
  def connect_to_new(tenant = nil)
64
74
  return reset if tenant.nil?
65
- # rubocop:disable Style/RaiseArgs
66
- raise ActiveRecord::StatementInvalid.new("Could not find schema #{tenant}") unless Apartment.connection.schema_exists?(tenant.to_s)
67
75
 
68
- # rubocop:enable Style/RaiseArgs
76
+ tenant = tenant.to_s
77
+ raise ActiveRecord::StatementInvalid, "Could not find schema #{tenant}" unless tenant_exists?(tenant)
69
78
 
70
- @current = tenant.to_s
79
+ @current = tenant
71
80
  Apartment.connection.schema_search_path = full_search_path
72
81
 
73
82
  # When the PostgreSQL version is < 9.3,
74
83
  # there is a issue for prepared statement with changing search_path.
75
84
  # https://www.postgresql.org/docs/9.3/static/sql-prepare.html
76
85
  Apartment.connection.clear_cache! if postgresql_version < 90_300
86
+ reset_sequence_names
77
87
  rescue *rescuable_exceptions
78
88
  raise TenantNotFound, "One of the following schema(s) is invalid: \"#{tenant}\" #{full_search_path}"
79
89
  end
80
90
 
81
91
  private
82
92
 
93
+ def tenant_exists?(tenant)
94
+ return true unless Apartment.tenant_presence_check
95
+
96
+ Apartment.connection.schema_exists?(tenant)
97
+ end
98
+
83
99
  def create_tenant_command(conn, tenant)
84
100
  conn.execute(%(CREATE SCHEMA "#{tenant}"))
85
101
  end
@@ -99,6 +115,24 @@ module Apartment
99
115
  # public from Rails 5.0.
100
116
  Apartment.connection.send(:postgresql_version)
101
117
  end
118
+
119
+ def reset_sequence_names
120
+ # sequence_name contains the schema, so it must be reset after switch
121
+ # There is `reset_sequence_name`, but that method actually goes to the database
122
+ # to find out the new name. Therefore, we do this hack to only unset the name,
123
+ # and it will be dynamically found the next time it is needed
124
+ descendants_to_unset = ActiveRecord::Base.descendants
125
+ .select { |c| c.instance_variable_defined?(:@sequence_name) }
126
+ .reject do |c|
127
+ c.instance_variable_defined?(:@explicit_sequence_name) &&
128
+ c.instance_variable_get(:@explicit_sequence_name)
129
+ end
130
+ descendants_to_unset.each do |c|
131
+ # NOTE: due to this https://github.com/rails-on-services/apartment/issues/81
132
+ # unreproduceable error we're checking before trying to remove it
133
+ c.remove_instance_variable :@sequence_name if c.instance_variable_defined?(:@sequence_name)
134
+ end
135
+ end
102
136
  end
103
137
 
104
138
  # Another Adapter for Postgresql when using schemas and SQL
@@ -166,9 +200,11 @@ module Apartment
166
200
  #
167
201
  # @return {String} raw SQL contaning inserts with data from schema_migrations
168
202
  #
203
+ # rubocop:disable Layout/LineLength
169
204
  def pg_dump_schema_migrations_data
170
205
  with_pg_env { `pg_dump -a --inserts -t #{default_tenant}.schema_migrations -t #{default_tenant}.ar_internal_metadata #{dbname}` }
171
206
  end
207
+ # rubocop:enable Layout/LineLength
172
208
 
173
209
  # Temporary set Postgresql related environment variables if there are in @config
174
210
  #