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/migration_mixin.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,
sig/ec/pg.rbs
Defined Under Namespace
Modules: Context, MigrationMixin, Mixin, RlsManager, RlsMixin, SchemaManager, SchemaMixin, SchemaRegistry, SchemaRegistryMixin, ShardManager, ShardMixin, TenantContext
Classes: Configuration, ContextSwitcher, Error, InvalidType, Migrator, Railtie
Constant Summary
collapse
- MINOR =
10
- VERSION =
"0.1.#{MINOR}"
Class Method Summary
collapse
Class Method Details
.clear_context! ⇒ Object
Clears all thread-local context.
.configuration ⇒ Object
50
51
52
|
# File 'lib/ec/pg.rb', line 50
def configuration
@configuration ||= Ec::Pg::Configuration.new
end
|
46
47
48
|
# File 'lib/ec/pg.rb', line 46
def configure
yield configuration
end
|
.dprint(message, color: :white) ⇒ Object
40
41
42
43
44
|
# File 'lib/ec/pg.rb', line 40
def dprint(message, color: :white)
if ENV['ECPG_DEBUG']
puts message.colorize(color)
end
end
|
.each_shard(&block) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/ec/pg.rb', line 64
def each_shard(&block)
shards.each do |shard|
Ec::Pg.switch(shard: shard) do
yield(shard)
end
end
end
|
.shards ⇒ Object
58
59
60
61
62
|
# File 'lib/ec/pg.rb', line 58
def shards
@shards ||= configuration.number_of_shards.times.map do |index|
"shard_#{index + 1}"
end
end
|
.switch(shard: nil, schema: nil, &block) ⇒ Object
54
55
56
|
# File 'lib/ec/pg.rb', line 54
def switch(shard: nil, schema: nil, &block)
TenantContext.switch(shard: shard, schema: schema, &block)
end
|