Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Extended by:
- ActiveRecordShards::ConfigurationParser, ActiveRecordShards::ConnectionSwitcher, ActiveRecordShards::DefaultSlavePatches, 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::DefaultSlavePatches
ActiveRecordShards::DefaultSlavePatches::CLASS_SLAVE_METHODS
Class Method Summary collapse
Methods included from ActiveRecordShards::ConfigurationParser
configurations_with_shard_explosion=, expand_child!, explode, extended
Methods included from ActiveRecordShards::Model
extended, is_sharded?, not_sharded, on_slave_by_default=, on_slave_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_master, on_master_if, on_master_or_slave, on_master_unless, on_shard, on_slave, on_slave?, on_slave_if, on_slave_unless, shard_names, shards, supports_sharding?
Methods included from ActiveRecordShards::DefaultSlavePatches
columns_with_force_slave, extended, on_slave_unless_tx, table_exists_with_force_slave?, transaction_with_slave_off, wrap_method_in_on_slave
Class Method Details
.establish_connection(spec = ENV["DATABASE_URL"]) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_record_shards/connection_specification.rb', line 4 def establish_connection(spec = ENV["DATABASE_URL"]) if ActiveRecord::VERSION::MAJOR >= 4 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) else resolver = ActiveRecordShards::ConnectionSpecification::Resolver.new spec, configurations spec = resolver.spec end 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 if ActiveRecord::VERSION::MAJOR >= 4 connection_handler.establish_connection self, spec else connection_handler.establish_connection connection_pool_name, spec end end |