pg_rls 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 492256f8c775835d6ed888cc64e93bff4c0a3f9583eb9c459e1ed9a5520d7fab
4
- data.tar.gz: f05611afd74ad000316df9622663de94d8feda84538de06cf5c548e749a60302
3
+ metadata.gz: 0e815f8e1e99ddf19dcd53be6876034dbeb535985c46ab7111555ac0fa02c02a
4
+ data.tar.gz: 4ce207b4766242cdc97940b313bb9a8ea864250ebd953bf4c36168d6ceced848
5
5
  SHA512:
6
- metadata.gz: cabd8e2479dbf5432a26b34680932a6ff2a4b1d2f6cbd6c1c369d8f4b954a69baa4cfefe8a81f86995b07f2a966a8129d664adf9115de23c0dbb3a91623cc52a
7
- data.tar.gz: 4f66a3686927071d5aa5f66374a63450cda26c9be6ebc86d1cf085fc373f90033e2e7d2fe50f4b1945452088122df3884ca5cd97746c43905615858cccf5fed6
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.10'
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
@@ -54,7 +55,6 @@ module PgRls
54
55
  def establish_new_connection!(admin: false)
55
56
  self.as_db_admin = admin
56
57
 
57
- db_config = PgRls.main_model.connection_db_config.configuration_hash
58
58
  execute_rls_in_shards do |connection_class, pool|
59
59
  connection_class.connection_pool.disconnect!
60
60
  connection_class.remove_connection
@@ -141,11 +141,9 @@ module PgRls
141
141
  end
142
142
 
143
143
  def execute_query_or_block(query = nil, &)
144
- if block_given?
145
- ensure_block_execution(&)
146
- else
147
- execute(query)
148
- end
144
+ return ensure_block_execution(&) if block_given?
145
+
146
+ execute(query)
149
147
  end
150
148
 
151
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.10
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-07-05 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