ec-pg 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -24
- data/ec-pg-0.1.0.gem +0 -0
- data/images/stand-with-palestine.webp +0 -0
- data/lib/ec/pg/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b9ec86d4b4b9d392a3e5e44e351d65db5ad63c235f020a0d88caea00bae9ef2
|
|
4
|
+
data.tar.gz: 27ebb8b0305434b3d2ac0c95a8c7c4a90a154a34bd23e26e32bb1aa2aa1be1de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1826c3c01d3b71359ca37f3ce7d87bb3d185393d27a16db764b01500c9f97a7596339d6efae18722784859cdf30d7c5e67e07281bdfad007bde5ca5576e19efc
|
|
7
|
+
data.tar.gz: 131d22a8df88213fab0833e59d3a74b74096753adadd0d4d780f04ee56305144d18c9f7c640588a4993b7b6aff6a6ad6a0f5a38066acd7003d72732d31caab59
|
data/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<img src="images/stand-with-palestine.webp" alt="Alt Text" width="200" style="float:right">
|
|
1
2
|
# ec-pg
|
|
2
3
|
|
|
3
4
|
Multi-tenancy for Rails + PostgreSQL. Supports three isolation strategies — schema-per-tenant, database sharding, and row-level security (RLS) — with thread-safe context management and optional Rack middleware for automatic per-request switching.
|
|
@@ -11,7 +12,7 @@ Multi-tenancy for Rails + PostgreSQL. Supports three isolation strategies — sc
|
|
|
11
12
|
## Installation
|
|
12
13
|
|
|
13
14
|
```ruby
|
|
14
|
-
gem 'ec-pg'
|
|
15
|
+
gem 'ec-pg'
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
## Strategies
|
|
@@ -35,18 +36,19 @@ Ec::Pg.configure do |c|
|
|
|
35
36
|
c.shared_schemas = ['public'] # always appended to search_path
|
|
36
37
|
c.number_of_shards = 4 # total shards in the cluster
|
|
37
38
|
c.rls_mode = :local # :local (per-transaction) or :session
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
##### BEGIN: Specific for ContextSwitcher middleware
|
|
40
41
|
# Return a hash with :shard and/or :schema keys.
|
|
41
42
|
c.get_context_method = ->(request) {
|
|
42
|
-
|
|
43
|
-
{ schema:
|
|
43
|
+
tenant = Tenant.find_by(host: reques.host)
|
|
44
|
+
{ schema: tenant.schema_identifier, shard: tenant.shard_identifier }
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
# Paths that bypass context switching (substring match)
|
|
47
48
|
c.context_switch_exclude_paths = ['health', 'status', 'metrics']
|
|
48
49
|
|
|
49
50
|
c.logger = Logger.new($stdout)
|
|
51
|
+
##### END
|
|
50
52
|
end
|
|
51
53
|
```
|
|
52
54
|
|
|
@@ -217,25 +219,6 @@ Context is stored in thread-local variables. Each thread/fiber has its own isola
|
|
|
217
219
|
|
|
218
220
|
---
|
|
219
221
|
|
|
220
|
-
## Low-level context API
|
|
221
|
-
|
|
222
|
-
```ruby
|
|
223
|
-
# Read
|
|
224
|
-
Ec::Pg::Context.shard # => :shard_one or nil
|
|
225
|
-
Ec::Pg::Context.schema # => 'acme' or nil
|
|
226
|
-
Ec::Pg::Context.current # => { shard: :shard_one, schema: 'acme' }
|
|
227
|
-
Ec::Pg::Context.active? # => true if any key is set
|
|
228
|
-
|
|
229
|
-
# Write
|
|
230
|
-
Ec::Pg::Context.set(shard: :shard_one, schema: 'acme')
|
|
231
|
-
Ec::Pg::Context.delete(:shard)
|
|
232
|
-
Ec::Pg::Context.clear!
|
|
233
|
-
|
|
234
|
-
# Temporary override (block-scoped)
|
|
235
|
-
Ec::Pg::Context.with(schema: 'other') { ... }
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
---
|
|
239
222
|
|
|
240
223
|
## Development
|
|
241
224
|
|
data/ec-pg-0.1.0.gem
ADDED
|
Binary file
|
|
Binary file
|
data/lib/ec/pg/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ec-pg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- gmhawash
|
|
@@ -120,6 +120,8 @@ files:
|
|
|
120
120
|
- README.md
|
|
121
121
|
- Rakefile
|
|
122
122
|
- config/locales/en.yml
|
|
123
|
+
- ec-pg-0.1.0.gem
|
|
124
|
+
- images/stand-with-palestine.webp
|
|
123
125
|
- lib/ec/pg.rb
|
|
124
126
|
- lib/ec/pg/configuration.rb
|
|
125
127
|
- lib/ec/pg/context.rb
|