pg_rls 0.1.9 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bc1212df6e6ab132c3772bf7b88e6ceac339f691ab826f6128c714c106d0012
4
- data.tar.gz: bc232e7a0c941f8da38c0e58c3e9bb373651379e137c8c2cb45eb139ddda560a
3
+ metadata.gz: 0e815f8e1e99ddf19dcd53be6876034dbeb535985c46ab7111555ac0fa02c02a
4
+ data.tar.gz: 4ce207b4766242cdc97940b313bb9a8ea864250ebd953bf4c36168d6ceced848
5
5
  SHA512:
6
- metadata.gz: 01bc710caa9f3917eba70423b9270ee564861af86f2efb544199a1ba126b521cecfb5601c47d72f223ec78ef26b6d1f3470d29be92bedf2b07550ceb94fd7a1c
7
- data.tar.gz: f9e2589ac082c4024a7c4c7afe43b2454c0de0793ae2a6dfee45b1af1b63fb32ea0550b711b25938c5b032d039351cbcddb2baf0184d46f454f422b0ec27a88b
6
+ metadata.gz: 9369bf467e43421b42093783428b3fdb544806ee378ad67e43500fecd530e971bc50b3671faf7cb54d126281bf21c5f88a7f9bb3eeffa52bdce0068578cfae04
7
+ data.tar.gz: d6fef41724951488a13c21fad439cc3f1f0c781e918d022f426adce50d81e8133f98961695042143dd8c6f96a229d8e6d42baed8cadf563b14b5ece4f8960611
data/Gemfile CHANGED
@@ -17,4 +17,5 @@ gem 'rubocop-performance'
17
17
  gem 'rubocop-rails'
18
18
  gem 'rubocop-rake'
19
19
  gem 'rubocop-rspec'
20
+ gem 'sidekiq'
20
21
  gem 'solargraph'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_rls (0.1.6)
4
+ pg_rls (0.1.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -109,6 +109,7 @@ GEM
109
109
  kramdown-parser-gfm (1.1.0)
110
110
  kramdown (~> 2.0)
111
111
  language_server-protocol (3.17.0.3)
112
+ logger (1.6.0)
112
113
  loofah (2.21.4)
113
114
  crass (~> 1.0.2)
114
115
  nokogiri (>= 1.12.0)
@@ -184,6 +185,8 @@ GEM
184
185
  rbs (2.8.4)
185
186
  rdoc (6.5.0)
186
187
  psych (>= 4.0.0)
188
+ redis-client (0.22.2)
189
+ connection_pool
187
190
  regexp_parser (2.8.2)
188
191
  reline (0.3.9)
189
192
  io-console (~> 0.5)
@@ -236,6 +239,12 @@ GEM
236
239
  rubocop-factory_bot (~> 2.22)
237
240
  ruby-progressbar (1.13.0)
238
241
  ruby2_keywords (0.0.5)
242
+ sidekiq (7.3.1)
243
+ concurrent-ruby (< 2)
244
+ connection_pool (>= 2.3.0)
245
+ logger
246
+ rack (>= 2.2.4)
247
+ redis-client (>= 0.22.2)
239
248
  solargraph (0.49.0)
240
249
  backport (~> 1.2)
241
250
  benchmark
@@ -268,6 +277,7 @@ GEM
268
277
 
269
278
  PLATFORMS
270
279
  arm64-darwin-22
280
+ arm64-darwin-23
271
281
  x86_64-linux
272
282
 
273
283
  DEPENDENCIES
@@ -280,6 +290,7 @@ DEPENDENCIES
280
290
  rubocop-rails
281
291
  rubocop-rake
282
292
  rubocop-rspec
293
+ sidekiq
283
294
  solargraph
284
295
 
285
296
  RUBY VERSION
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgRls
4
+ # Current Context
5
+ module Current
6
+ class Context < ActiveSupport::CurrentAttributes
7
+ attribute :tenant
8
+ end
9
+ end
10
+ end
data/lib/pg_rls/tenant.rb CHANGED
@@ -36,7 +36,7 @@ module PgRls
36
36
  end
37
37
 
38
38
  def fetch!
39
- PgRls.main_model.find_by!(
39
+ PgRls::Current::Context.tenant ||= PgRls.main_model.find_by!(
40
40
  tenant_id: PgRls.connection_class.connection.execute(
41
41
  "SELECT current_setting('rls.tenant_id')"
42
42
  ).getvalue(0, 0)
@@ -50,6 +50,7 @@ module PgRls
50
50
  end
51
51
  end
52
52
 
53
+ PgRls::Current::Context.clear_all
53
54
  nil
54
55
  end
55
56
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRls
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.11'
5
5
  end
data/lib/pg_rls.rb CHANGED
@@ -11,6 +11,7 @@ require_relative 'pg_rls/tenant'
11
11
  require_relative 'pg_rls/multi_tenancy'
12
12
  require_relative 'pg_rls/railtie' if defined?(Rails)
13
13
  require_relative 'pg_rls/errors/index'
14
+ require_relative 'pg_rls/current/context'
14
15
 
15
16
  ActiveRecord::Migrator.prepend PgRls::Admin::ActiveRecord::Migrator
16
17
  ActiveRecord::Tasks::DatabaseTasks.prepend PgRls::Admin::ActiveRecord::Tasks::DatabaseTasks
@@ -32,8 +33,10 @@ module PgRls
32
33
 
33
34
  def setup
34
35
  ActiveRecord::Base.ignored_columns += %w[tenant_id]
36
+
35
37
  yield self
36
- Rails.application.config.after_initialize do
38
+
39
+ Rails.application.config.to_prepare do
37
40
  PgRls.main_model.ignored_columns = []
38
41
  end
39
42
  end
@@ -52,7 +55,6 @@ module PgRls
52
55
  def establish_new_connection!(admin: false)
53
56
  self.as_db_admin = admin
54
57
 
55
- db_config = PgRls.main_model.connection_db_config.configuration_hash
56
58
  execute_rls_in_shards do |connection_class, pool|
57
59
  connection_class.connection_pool.disconnect!
58
60
  connection_class.remove_connection
@@ -139,11 +141,9 @@ module PgRls
139
141
  end
140
142
 
141
143
  def execute_query_or_block(query = nil, &)
142
- if block_given?
143
- ensure_block_execution(&)
144
- else
145
- execute(query)
146
- end
144
+ return ensure_block_execution(&) if block_given?
145
+
146
+ execute(query)
147
147
  end
148
148
 
149
149
  def reset_connection_if_needed(current_tenant, reset_rls_connection)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Laloush
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  This gem will help you to integrate PostgreSQL RLS to help you develop a great multitenancy application
@@ -47,6 +47,7 @@ files:
47
47
  - lib/generators/templates/pg_rls.rb.tt
48
48
  - lib/pg_rls.rb
49
49
  - lib/pg_rls/Rakefile
50
+ - lib/pg_rls/current/context.rb
50
51
  - lib/pg_rls/database/admin_statements.rb
51
52
  - lib/pg_rls/database/configurations.rb
52
53
  - lib/pg_rls/database/prepared.rb
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  - !ruby/object:Gem::Version
87
88
  version: '0'
88
89
  requirements: []
89
- rubygems_version: 3.4.10
90
+ rubygems_version: 3.5.11
90
91
  signing_key:
91
92
  specification_version: 4
92
93
  summary: Write a short summary, because RubyGems requires one.