pg_rls 0.0.1.4.2 → 0.0.1.4.3

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: 7c49344c7e0967e1afe2cf3f982678fcdae6edec8766fa92ed51f644594be84e
4
- data.tar.gz: 21812122d43412184edefcc4cbe45ba7a160ff5d335f01de8f4962b20fb6e5e6
3
+ metadata.gz: 05d5356859c19958958aaf0c3160e2bafc66a5b3464b542b4087e8684b70dd7c
4
+ data.tar.gz: 2e53e808f31b07293ea6b1071f8e237be72d483964df2d4313c1215973a07fcd
5
5
  SHA512:
6
- metadata.gz: f423f4793439745830715c5a6058c3703445185dee9e0219ceb68c09a57dcd728ddc758daa35947fef94c0248b7cf075ba73452c9eb2e4ee79e8d8d344ab78d9
7
- data.tar.gz: 2ad9bb3bac5e097f708075d44b08755621f2cf8202f6a9894dc7171e5ffd728f072d10f61d9df8aabc72297a453ae065088ddf4e403a16f8bb0fc2e2c1d29f7e
6
+ metadata.gz: b4535bef8f1ed1595cd2639a2db3168c3c0d67b5f94db461bead0d1c00e94fec492e4dbf6a8481baa3f76e102946ec95ab6eed5f2930ecd010feb5d90c1f9da5
7
+ data.tar.gz: 2c14bc491065d684f962a122923fbbba7e40766a02fc870c91d15655ba7a204a1aaec7656e45ae6f11cc2245a56b8327e861dba721a92fc06bb7a62660216952
data/Gemfile.lock CHANGED
@@ -2,7 +2,7 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  pg_rls (0.0.1.4.2)
5
- bundler (>= 2.2.10)
5
+ bundler (~> 2.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -20,25 +20,19 @@ module PgRls
20
20
  end
21
21
 
22
22
  def create_tenant_migration_file
23
- return if migration_exist?
24
-
25
- migration_template create_migration_template_path,
23
+ migration_template(create_migration_template_path,
26
24
  "#{migration_path}/#{create_file_sub_name}_#{table_name}.rb",
27
- migration_version: migration_version
25
+ migration_version: migration_version) if creating?
28
26
  end
29
27
 
30
28
  def convert_tenant_migration_file
31
- return unless migration_exist?
32
-
33
- migration_template convert_migration_template_path,
29
+ migration_template(convert_migration_template_path,
34
30
  "#{migration_path}/#{convert_file_sub_name}_#{table_name}.rb",
35
- migration_version: migration_version
31
+ migration_version: migration_version) unless creating?
36
32
 
37
- return if installation_in_progress?
38
-
39
- migration_template 'convert_migration_backport.rb.tt',
33
+ migration_template('convert_migration_backport.rb.tt',
40
34
  "#{migration_path}/pg_rls_backport_#{table_name}.rb",
41
- migration_version: migration_version
35
+ migration_version: migration_version) if installation_in_progress?
42
36
  end
43
37
 
44
38
  def create_model_file
@@ -103,6 +97,10 @@ module PgRls
103
97
  db_migrate_path
104
98
  end
105
99
 
100
+ def creating?
101
+ @creating ||= !migration_exist?
102
+ end
103
+
106
104
  protected
107
105
 
108
106
  def migration_action() = 'add'
@@ -11,7 +11,7 @@ module PgRls
11
11
  include DownStatements
12
12
 
13
13
  def create_rls_tenant_table(table_name, **options, &block)
14
- create_rls_user(password: PgRls.database_configuration['password'])
14
+ create_rls_user(password: PgRls.database_default_configuration[:password])
15
15
  create_rls_setter_function
16
16
  create_rls_blocking_function
17
17
  create_table(table_name, **options, &block)
@@ -41,7 +41,7 @@ module PgRls
41
41
  end
42
42
 
43
43
  def convert_to_rls_tenant_table(table_name, **_options)
44
- create_rls_user(password: PgRls.database_configuration['password'])
44
+ create_rls_user(password: PgRls.database_default_configuration[:password])
45
45
  create_rls_setter_function
46
46
  create_rls_blocking_function
47
47
  add_rls_column_to_tenant_table(table_name)
@@ -6,19 +6,28 @@ module PgRls
6
6
  module UpStatements
7
7
  def create_rls_user(name: PgRls::SECURE_USERNAME, password: 'password')
8
8
  PgRls.execute <<-SQL
9
- DROP ROLE IF EXISTS #{name};
10
- CREATE USER #{name} WITH PASSWORD '#{password}';
11
- GRANT ALL PRIVILEGES ON TABLE schema_migrations TO #{name};
12
- GRANT USAGE ON SCHEMA public TO #{name};
13
- ALTER DEFAULT PRIVILEGES IN SCHEMA public
14
- GRANT SELECT, INSERT, UPDATE, DELETE
15
- ON TABLES TO #{name};
16
- GRANT SELECT, INSERT, UPDATE, DELETE
17
- ON ALL TABLES IN SCHEMA public
18
- TO #{name};
19
- GRANT USAGE, SELECT
20
- ON ALL SEQUENCES IN SCHEMA public
21
- TO #{name};
9
+ DO
10
+ $do$
11
+ BEGIN
12
+ IF NOT EXISTS (
13
+ SELECT FROM pg_catalog.pg_roles -- SELECT list can be empty for this
14
+ WHERE rolname = '#{name}') THEN
15
+
16
+ CREATE USER #{name} WITH PASSWORD '#{password}';
17
+ GRANT ALL PRIVILEGES ON TABLE schema_migrations TO #{name};
18
+ GRANT USAGE ON SCHEMA public TO #{name};
19
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public
20
+ GRANT SELECT, INSERT, UPDATE, DELETE
21
+ ON TABLES TO #{name};
22
+ GRANT SELECT, INSERT, UPDATE, DELETE
23
+ ON ALL TABLES IN SCHEMA public
24
+ TO #{name};
25
+ GRANT USAGE, SELECT
26
+ ON ALL SEQUENCES IN SCHEMA public
27
+ TO #{name};
28
+ END IF;
29
+ END
30
+ $do$;
22
31
  SQL
23
32
  end
24
33
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRls
4
- VERSION = '0.0.1.4.2'
4
+ VERSION = '0.0.1.4.3'
5
5
  end
data/lib/pg_rls.rb CHANGED
@@ -94,10 +94,14 @@ module PgRls
94
94
  ActiveRecord::Migration.execute(query)
95
95
  end
96
96
 
97
+ def database_default_configuration
98
+ connection_class.connection.pool.db_config.configuration_hash
99
+ end
100
+
97
101
  def database_configuration
98
- database_connection_file[Rails.env].tap do |config|
99
- config['username'] = PgRls::SECURE_USERNAME unless default_connection?
100
- end
102
+ current_configuration = database_default_configuration.deep_dup
103
+ current_configuration.tap { |config| config[:username] = PgRls::SECURE_USERNAME unless default_connection? }
104
+ current_configuration.freeze
101
105
  end
102
106
  end
103
107
  mattr_accessor :table_name
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.0.1.4.2
4
+ version: 0.0.1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Laloush
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-07 00:00:00.000000000 Z
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.0'
88
+ version: '3.1'
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - ">="