diff --git a/lib/apartment.rb b/lib/apartment.rb index 0bf253f1..b074f5da 100644 --- a/lib/apartment.rb +++ b/lib/apartment.rb @@ -19,7 +19,7 @@ class << self ACCESSOR_METHODS = %i[use_schemas use_sql seed_after_create prepend_environment default_tenant append_environment with_multi_server_setup tenant_presence_check active_record_log].freeze - WRITER_METHODS = %i[tenant_names database_schema_file excluded_models + WRITER_METHODS = %i[use_sharding unshard_models tenant_names database_schema_file excluded_models persistent_schemas connection_class db_migrate_tenants db_migrate_tenant_missing_strategy seed_data_file parallel_migration_threads pg_excluded_names].freeze @@ -90,6 +90,14 @@ def persistent_schemas @persistent_schemas || [] end + def use_sharding + @use_sharding || false + end + + def unshard_models + @unshard_models || [] + end + def connection_class @connection_class || ActiveRecord::Base end diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index c15514da..f9107299 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -64,6 +64,20 @@ def tenant_names_from_array(names) expect(described_class.active_record_log).to be true end + it 'sets use_sharding' do + described_class.configure do |config| + config.use_sharding = true + end + expect(described_class.use_sharding).to be true + end + + it 'sets unshard_models' do + described_class.configure do |config| + config.unshard_models = ['GlobalRecord'] + end + expect(described_class.unshard_models).to eq(['GlobalRecord']) + end + context 'when databases' do let(:users_conf_hash) { { port: 5444 } }