Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add use of sharding and unshard models to config #1

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/apartment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }

Expand Down