rls_multi_tenant 0.1.5 → 0.1.6

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: f313946d33d5edb4a96fec341e7ab62fc325ab0d6700bad0aef7b05d6f240ec4
4
- data.tar.gz: 0bbbdf115873c98b5487569cd21e63822fd1b2419b7eec55bbb875a5c131a417
3
+ metadata.gz: 8c3310349a1bab642ea0facd9a4199d3b63e075e9eb15905b00a86075285f891
4
+ data.tar.gz: '06494c0144141a2ad9ac97b57091ebfc7198472342d9b7a9e5da2609e5928c9a'
5
5
  SHA512:
6
- metadata.gz: fe257329e8fff95796cc6b4510ce1672ddf16e86b572d0113fedcc902afa69fc7e13d925b4d2d5e0a0bb1a6bcc5692e1bdc477fe8aab365b4b838d3fbedf124f
7
- data.tar.gz: 4ad4b27347d478b42e720c33c178eb655860d93809f0403fa58ff5197dbae98e563064e654ea51bdbabf0c3ae272e5871de402e1f6785fac0b3e39971a890341
6
+ metadata.gz: 4231b3ec6287ef0bb2223284b991c7951149ab2f608c755a823b451a6527134ce64a11a24b988a74e62ebc692585aaedb99d738b8a7055d01b570cff4cc354d9
7
+ data.tar.gz: 640196b111037946feee80e8a516d32f0a09b00512c277cff68dd1c011794d3f7b827490b0c003810642c90151b06ef14ab02223bd8b1bc85fae741803b161f3
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rails/generators'
4
+ require 'rls_multi_tenant/generators/shared/template_helper'
4
5
 
5
6
  module RlsMultiTenant
6
7
  module Generators
7
8
  class InstallGenerator < Rails::Generators::Base
9
+ include Shared::TemplateHelper
10
+
8
11
  source_root File.expand_path("templates", __dir__)
9
12
 
10
13
  desc "Install RLS Multi-tenant gem configuration"
@@ -13,6 +16,14 @@ module RlsMultiTenant
13
16
  template "rls_multi_tenant.rb", "config/initializers/rls_multi_tenant.rb"
14
17
  end
15
18
 
19
+ def create_db_admin_task
20
+ unless File.exist?(File.join(destination_root, "lib/tasks/db_admin.rake"))
21
+ copy_shared_template "db_admin.rake", "lib/tasks/db_admin.rake"
22
+ else
23
+ say "Database admin task already exists, skipping creation", :yellow
24
+ end
25
+ end
26
+
16
27
  def show_instructions
17
28
  say "\n" + "="*60, :green
18
29
  say "RLS Multi-tenant gem configuration installed successfully!", :green
@@ -7,15 +7,9 @@ class EnableRlsFor<%= table_name.camelize %> < ActiveRecord::Migration[<%= Rails
7
7
 
8
8
  # Create RLS policy
9
9
  execute "CREATE POLICY <%= table_name %>_app_user ON <%= table_name %> TO #{ENV['<%= RlsMultiTenant.app_user_env_var %>']} USING (<%= RlsMultiTenant.tenant_id_column %> = NULLIF(current_setting('rls.<%= RlsMultiTenant.tenant_id_column %>', TRUE), '')::uuid)"
10
-
11
- # Grant permissions
12
- execute "GRANT SELECT, INSERT, UPDATE, DELETE ON <%= table_name %> TO #{ENV['<%= RlsMultiTenant.app_user_env_var %>']}"
13
10
  end
14
11
 
15
12
  dir.down do
16
- # Revoke permissions
17
- execute "REVOKE SELECT, INSERT, UPDATE, DELETE ON <%= table_name %> FROM #{ENV['<%= RlsMultiTenant.app_user_env_var %>']}"
18
-
19
13
  # Drop policy
20
14
  execute "DROP POLICY <%= table_name %>_app_user ON <%= table_name %>"
21
15
 
@@ -13,15 +13,6 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= Rails.version.to
13
13
  # Enable Row Level Security
14
14
  execute "ALTER TABLE <%= table_name %> ENABLE ROW LEVEL SECURITY"
15
15
 
16
- reversible do |dir|
17
- dir.up do
18
- execute "GRANT SELECT, INSERT, UPDATE, DELETE ON <%= table_name %> TO #{ENV['<%= RlsMultiTenant.app_user_env_var %>']}"
19
- end
20
- dir.down do
21
- execute "REVOKE SELECT, INSERT, UPDATE, DELETE ON <%= table_name %> FROM #{ENV['<%= RlsMultiTenant.app_user_env_var %>']}"
22
- end
23
- end
24
-
25
16
  # Define RLS policy
26
17
  reversible do |dir|
27
18
  dir.up do
@@ -23,14 +23,6 @@ module RlsMultiTenant
23
23
  end
24
24
  end
25
25
 
26
- def create_db_admin_task
27
- unless File.exist?(File.join(destination_root, "lib/tasks/db_admin.rake"))
28
- copy_shared_template "db_admin.rake", "lib/tasks/db_admin.rake"
29
- else
30
- say "Database admin task already exists, skipping creation", :yellow
31
- end
32
- end
33
-
34
26
  def create_uuid_migration
35
27
  unless Dir.glob(File.join(destination_root, "db/migrate/*_enable_uuid_extension.rb")).any?
36
28
  create_migration_with_timestamp("enable_uuid", 1)
@@ -61,7 +53,6 @@ module RlsMultiTenant
61
53
  say "="*60, :green
62
54
  say "\nCreated:", :yellow
63
55
  say "• #{tenant_class_name} model", :green
64
- say "• Database admin task", :green
65
56
  say "• UUID extension migration", :green
66
57
  say "• App user migration(s)", :green
67
58
  say "• #{tenant_class_name} migration", :green
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RlsMultiTenant
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rls_multi_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coding Ways