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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/pg_rls/active_record/active_record_generator.rb +10 -12
- data/lib/pg_rls/schema/statements.rb +2 -2
- data/lib/pg_rls/schema/up_statements.rb +22 -13
- data/lib/pg_rls/version.rb +1 -1
- data/lib/pg_rls.rb +7 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05d5356859c19958958aaf0c3160e2bafc66a5b3464b542b4087e8684b70dd7c
|
4
|
+
data.tar.gz: 2e53e808f31b07293ea6b1071f8e237be72d483964df2d4313c1215973a07fcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4535bef8f1ed1595cd2639a2db3168c3c0d67b5f94db461bead0d1c00e94fec492e4dbf6a8481baa3f76e102946ec95ab6eed5f2930ecd010feb5d90c1f9da5
|
7
|
+
data.tar.gz: 2c14bc491065d684f962a122923fbbba7e40766a02fc870c91d15655ba7a204a1aaec7656e45ae6f11cc2245a56b8327e861dba721a92fc06bb7a62660216952
|
data/Gemfile.lock
CHANGED
@@ -20,25 +20,19 @@ module PgRls
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def create_tenant_migration_file
|
23
|
-
|
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
|
-
|
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
|
-
|
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.
|
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.
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
|
data/lib/pg_rls/version.rb
CHANGED
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
|
-
|
99
|
-
|
100
|
-
|
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.
|
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-
|
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.
|
88
|
+
version: '3.1'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
91
|
- - ">="
|