Module: Ec::Pg

Defined in:
lib/ec/pg.rb,
lib/ec/pg/mixin.rb,
lib/ec/pg/context.rb,
lib/ec/pg/railtie.rb,
lib/ec/pg/version.rb,
lib/ec/pg/migrator.rb,
lib/ec/pg/rls_mixin.rb,
lib/ec/pg/rls_manager.rb,
lib/ec/pg/shard_mixin.rb,
lib/ec/pg/schema_mixin.rb,
lib/ec/pg/configuration.rb,
lib/ec/pg/shard_manager.rb,
lib/ec/pg/schema_manager.rb,
lib/ec/pg/tenant_context.rb,
lib/ec/pg/schema_registry/mixin.rb,
lib/ec/pg/schema_registry_mixin.rb,
lib/ec/pg/schema_registry/cloner.rb,
lib/ec/pg/middleware/context_switcher.rb,
lib/ec/pg/schema_registry/schema_migration_cloner.rb

Defined Under Namespace

Modules: Context, Mixin, RlsManager, RlsMixin, SchemaManager, SchemaMixin, SchemaRegistry, SchemaRegistryMixin, ShardManager, ShardMixin, TenantContext Classes: Configuration, ContextSwitcher, Error, InvalidType, Migrator, Railtie

Constant Summary collapse

VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.clear_context!Object

Clears all thread-local context.



75
# File 'lib/ec/pg.rb', line 75

def clear_context! = TenantContext.clear_context!

.configurationObject



49
50
51
# File 'lib/ec/pg.rb', line 49

def configuration
  @configuration ||= Ec::Pg::Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



45
46
47
# File 'lib/ec/pg.rb', line 45

def configure
  yield configuration
end

.current_schemaObject



72
# File 'lib/ec/pg.rb', line 72

def current_schema = TenantContext.current_schema

.current_shardObject



71
# File 'lib/ec/pg.rb', line 71

def current_shard = TenantContext.current_shard

.dprint(*args) ⇒ Object



39
40
41
42
43
# File 'lib/ec/pg.rb', line 39

def dprint(*args)
  if ENV['ECPG_DEBUG']
    puts args
  end
end

.each_shard(&block) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/ec/pg.rb', line 63

def each_shard(&block)
  shards.each do |shard|
    Ec::Pg.switch(shard: shard) do 
      yield(shard)
    end
  end
end

.shardsObject



57
58
59
60
61
# File 'lib/ec/pg.rb', line 57

def shards 
  @shards ||= configuration.number_of_shards.times.map do |index|
    "shard_#{index + 1}"
  end
end

.switch(shard: nil, schema: nil, &block) ⇒ Object



53
54
55
# File 'lib/ec/pg.rb', line 53

def switch(shard: nil, schema: nil, &block)
  TenantContext.switch(shard: shard, schema: schema, &block)
end