Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Extended by:
- ActiveRecordShards::ConfigurationParser, ActiveRecordShards::ConnectionSwitcher, ActiveRecordShards::DefaultReplicaPatches, ActiveRecordShards::Model
- Defined in:
- lib/active_record_shards/connection_specification.rb
Constant Summary
Constants included from ActiveRecordShards::ConnectionSwitcher
ActiveRecordShards::ConnectionSwitcher::SHARD_NAMES_CONFIG_KEY
Constants included from ActiveRecordShards::DefaultReplicaPatches
ActiveRecordShards::DefaultReplicaPatches::CLASS_FORCE_REPLICA_METHODS, ActiveRecordShards::DefaultReplicaPatches::CLASS_FORCE_SLAVE_METHODS, ActiveRecordShards::DefaultReplicaPatches::CLASS_REPLICA_METHODS, ActiveRecordShards::DefaultReplicaPatches::CLASS_SLAVE_METHODS
Class Method Summary collapse
Methods included from ActiveRecordShards::ConfigurationParser
configurations_with_shard_explosion=, expand_child!, explode, extended, replace_slave_keys
Methods included from ActiveRecordShards::Model
extended, is_sharded?, not_sharded, on_replica_by_default=, on_replica_by_default?
Methods included from ActiveRecordShards::ConnectionSwitcher
connection_pool_name, connection_specification_name, current_shard_id, current_shard_selection, default_shard=, extended, on_all_shards, on_cx_switch_block, on_first_shard, on_primary, on_primary_db, on_primary_if, on_primary_or_replica, on_primary_unless, on_replica, on_replica?, on_replica_if, on_replica_unless, on_shard, reset_primary_key_with_default_shard, shard_names, shards, supports_sharding?
Methods included from ActiveRecordShards::DefaultReplicaPatches
extended, force_on_replica, on_replica_unless_tx, transaction_with_replica_off, wrap_method_in_on_replica, wrap_method_in_on_slave
Class Method Details
.establish_connection(spec = ENV["DATABASE_URL"]) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/active_record_shards/connection_specification.rb', line 5 def establish_connection(spec = ENV["DATABASE_URL"]) spec ||= ActiveRecord::ConnectionHandling::DEFAULT_ENV.call spec = spec.to_sym if spec.is_a?(String) resolver = ActiveRecordShards::ConnectionSpecification::Resolver.new configurations spec = resolver.spec(spec) unless respond_to?(spec.adapter_method) raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter" end remove_connection specification_cache[connection_pool_name] = spec connection_handler.establish_connection self, spec end |