Module: Sequel::SchemaSharding

Defined in:
lib/sequel/schema-sharding.rb,
lib/sequel/schema-sharding/ring.rb,
lib/sequel/schema-sharding/model.rb,
lib/sequel/schema-sharding/finder.rb,
lib/sequel/schema-sharding/version.rb,
lib/sequel/schema-sharding/logger_proxy.rb,
lib/sequel/schema-sharding/configuration.rb,
lib/sequel/schema-sharding/dtrace_provider.rb,
lib/sequel/schema-sharding/database_manager.rb,
lib/sequel/schema-sharding/connection_manager.rb,
lib/sequel/schema-sharding/extensions/migrations_ext.rb,
lib/sequel/schema-sharding/connection_strategies/random.rb,
lib/sequel/schema-sharding/connection_strategies/primary_with_failover.rb

Defined Under Namespace

Modules: ConnectionStrategy, Extensions, ShardedModel Classes: Configuration, ConnectionManager, DTraceProvider, DatabaseManager, Finder, LoggerProxy, Ring

Constant Summary collapse

VERSION =
"0.13.4"

Class Method Summary collapse

Class Method Details

.configObject



17
18
19
# File 'lib/sequel/schema-sharding.rb', line 17

def self.config
  @config ||= Sequel::SchemaSharding::Configuration.new(ENV['RACK_ENV'], sharding_yml_path)
end

.config=(config) ⇒ Object



21
22
23
# File 'lib/sequel/schema-sharding.rb', line 21

def self.config=(config)
  @config = config
end

.connection_managerObject



41
42
43
# File 'lib/sequel/schema-sharding.rb', line 41

def self.connection_manager
  @connection_manager ||= ConnectionManager.new
end

.connection_manager=(connection_manager) ⇒ Object



45
46
47
# File 'lib/sequel/schema-sharding.rb', line 45

def self.connection_manager=(connection_manager)
  @connection_manager = connection_manager
end

.loggerObject



33
34
35
# File 'lib/sequel/schema-sharding.rb', line 33

def self.logger
  @logger ||= Logger.new(nil)
end

.logger=(logger) ⇒ Object



37
38
39
# File 'lib/sequel/schema-sharding.rb', line 37

def self.logger=(logger)
  @logger = logger
end

.migration_pathObject



57
58
59
# File 'lib/sequel/schema-sharding.rb', line 57

def self.migration_path
  @migration_path || raise('You must set the migration path.')
end

.migration_path=(path) ⇒ Object



61
62
63
# File 'lib/sequel/schema-sharding.rb', line 61

def self.migration_path=(path)
  @migration_path = path
end

.Model(source) ⇒ Object

Extensions to the Sequel model to allow logical/physical shards. Actual table models should inherit this class like so:

class Cat < Sequel::SchemaSharding::Model

set_columns [:cat_id, :fur, :tongue, :whiskers] # Columns in the database need to be predefined.
set_sharded_column :cat_id # Define the shard column

def self.by_cat_id(id)
  # You should always call shard_for in finders to select the correct connection.
  shard_for(id).where(cat_id: id)
end

end



18
19
20
21
22
23
24
25
# File 'lib/sequel/schema-sharding/model.rb', line 18

def self.Model(source)
  klass = Sequel::Model(Sequel::SchemaSharding.connection_manager.default_dataset_for(source))

  klass.include(SchemaSharding::ShardedModel)
  klass.send(:simple_table=, false)

  klass
end

.replica_strategyObject



25
26
27
# File 'lib/sequel/schema-sharding.rb', line 25

def self.replica_strategy
  @replica_strategy ||= Sequel::SchemaSharding::ConnectionStrategy::Random
end

.replica_strategy=(strategy) ⇒ Object



29
30
31
# File 'lib/sequel/schema-sharding.rb', line 29

def self.replica_strategy=(strategy)
  @replica_strategy = strategy
end

.sharding_yml_pathObject



49
50
51
# File 'lib/sequel/schema-sharding.rb', line 49

def self.sharding_yml_path
  @sharding_yml_path ||= File.expand_path('../../../config/sharding.yml', __FILE__)
end

.sharding_yml_path=(path) ⇒ Object



53
54
55
# File 'lib/sequel/schema-sharding.rb', line 53

def self.sharding_yml_path=(path)
  @sharding_yml_path = path
end