pg_rls 0.0.1 → 0.0.1.1

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: c4f0bd5f9878604a5f34c33b24221a9e7bb1efe25b526c825044dd7927f870f6
4
- data.tar.gz: 1e51d31dccc7b7787921775f856d96cb630bf006fe5108df8fb65aba6560cf98
3
+ metadata.gz: 4adb2a4dc970c7945eea48bae37f3fe6153607ac61bfe69e5190a4f1b0d3996b
4
+ data.tar.gz: 6c223603207bb885e56b4e2340c0e737747418cfeca0fea9a0cda191385cc945
5
5
  SHA512:
6
- metadata.gz: 86bafd3671e72de8a0f7fb84891c76530a28065dfb799b06de600bb0199a41cd8c22fed269e44076f79a05e2d874e63eeeb7f5728518d15ceddf89e6ff7bf824
7
- data.tar.gz: f99445e75de533cb9ef7acfc5215c14ca78d629bd65cef1cb497f3adc1ae43f8689d46bcf7dcab8a5ac7684b79290630841ef33142434366800af9cf94e448d2
6
+ metadata.gz: 58a6a9f87ad417a3ce1783211afe6189fec242f7488cb238d9ec416c71b960eac7263b1c90cb6afa03460ab0b393d7af510e40b6d5d78484d4e56a89ba742982
7
+ data.tar.gz: bc5efaefc28e0b965ebeebc27151b96324399275f96a5ae473ea2336e220ff10f646490b35cbd3d7d5d92cefc55b88025502a8619bb32000ebb32bbbaefaf506
data/README.md CHANGED
@@ -4,28 +4,23 @@
4
4
  [![Issues][issues-shield]][issues-url]
5
5
  [![LinkedIn][linkedin-shield2]][linkedin-url2]
6
6
  [![Hireable][hireable]][hireable-url]
7
+ [![Donate][donate]][paypal-donate-code]
7
8
 
8
9
  <!-- PROJECT LOGO -->
9
10
  <br />
10
11
  <p align="center">
11
- <h1 align="center">PgRls</h1>
12
- <h2 align="center"> PostgreSQL Row Level Security </h2>
13
- <h1 align="center"></h1>
12
+ <h1 align="center">PgRls<h2 align="center">PostgreSQL Row Level Security<br />The Rails right way to do multitenancy</h2></h1>
14
13
 
15
14
  <p align="center">
16
15
  <br />
17
- <a href="https://github.com/Dandush03/pg_rls"><strong>Explore the docs »</strong></a>
16
+ <a href="https://github.com/Dandush03/pg_rls/wiki"><strong>Explore the docs »</strong></a>
18
17
  <br />
19
18
  <br />
20
- <a href="https://dl-final-webapp.herokuapp.com/">View Live Demo</a>
21
- ·
22
19
  <a href="https://github.com/Dandush03/pg_rls/issues">Report Bug</a>
23
20
  ·
24
21
  <a href="https://github.com/Dandush03/pg_rls/issues">Request Feature</a>
25
22
  ·
26
23
  <a href="https://github.com/Dandush03/pg_rls">API Repo</a>
27
- ·
28
- <a href="https://github.com/Dandush03/pg_rls">WebApp Repo</a>
29
24
  </p>
30
25
 
31
26
  </p>
@@ -34,6 +29,7 @@
34
29
  * [Required Installations](#required-Installations)
35
30
  * [Installing](#installing)
36
31
  * [Instructions](#instructions)
32
+ * [Testing](#Testing)
37
33
  * [Development](#testing)
38
34
  * [Contact](#contact)
39
35
  * [Contributing](#contributing)
@@ -41,9 +37,11 @@
41
37
  * [Code of Conduct](#Code-of-Conduct)
42
38
  * [Show your support](#Show-your-support)
43
39
 
44
- This gem will help you to integrate PostgreSQL RLS to help you develop an easy multitenancy application
40
+ ### It's time we start doing multitenancy right! You can avoid creating a separate Postgres schema/databases for each customer or trying to ensure the WHERE clause of every single query includes the particular company. Just integrate PgRls seamlessly to your application.
41
+
42
+ ### This gem will integrate PostgreSQL RLS to help you develop a great multitenancy application.
45
43
 
46
- ## Required Installations
44
+ ## Required Installation
47
45
  ### Installing
48
46
 
49
47
  Add this line to your application's Gemfile:
@@ -56,31 +54,49 @@ And then execute:
56
54
 
57
55
  $ bundle install
58
56
 
59
- Or install it yourself as:
57
+ Or install it yourself with:
60
58
 
61
59
  $ gem install pg_rls
62
60
 
63
61
  ### Instructions
64
62
 
65
63
  ```bash
66
- rails generate pg_rls:install company #=> where app eq tenant model name
64
+ rails generate pg_rls:install company #=> where company eq tenant model name
67
65
  ```
68
- You can change company to anything you'd like like for example `tenant`
69
- this will generate the model and inject all the required code
66
+ You can change company to anything you'd like, for example `tenant`
67
+ This will generate the model and inject all the required code
70
68
 
71
- for any new model that required to be under rls you can generate it by writing
69
+ For any new model that needs to be under rls, you can generate it by writing
72
70
 
73
71
  ```bash
74
- rails generate pg_rls user #=> where app eq model name
72
+ rails generate pg_rls user #=> where user eq model name
75
73
  ```
76
- and it will generate all the necesary information for you
74
+ and it will generate all the necesary information for you.
77
75
 
78
- you can swtich tenant by using
76
+ You can swtich to another tenant by using
79
77
  ```ruby
80
- PgRls::Tenant::switch :app #=> where app eq tenant name
78
+ PgRls::Tenant.switch :app #=> where app eq tenant name
81
79
  ```
82
80
 
83
- enjoy the gem :)
81
+ ### Testing
82
+
83
+ Many application uses some sort of database cleaner before running thair spec so on each test that we run we'll have an empty state. Usually, those gems clear our user configuration for the database. To solve this issue, we must implement the following:
84
+
85
+ ```ruby
86
+ # spec/rails_helper.rb
87
+
88
+ ...
89
+ # some database cleaning strategy
90
+
91
+ config.before(:suite) do
92
+ # Create A Default Tenant and Grant Test User Credentials
93
+ PgRls::Test::PreparedDatabase.grant_user_credentials
94
+ FactoryBot.create(:company, subdomain: 'app')
95
+ PgRls::Tenant.switch :app
96
+ end
97
+
98
+ ...
99
+ ```
84
100
  ## Development
85
101
 
86
102
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -100,12 +116,16 @@ The gem is available as open source under the terms of the [MIT License](https:/
100
116
  Everyone interacting in the PgRls project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dandush03/pg_rls/blob/master/CODE_OF_CONDUCT.md).
101
117
 
102
118
  ## Note
103
- Currently we only support subdomain as a searcher but soon will integrate slug/domain and cookies support
119
+ Currently we only support subdomain as a searcher but will soon integrate slug/domain and cookies support
104
120
 
105
121
  ## Show your support
106
122
 
107
123
  Give a ⭐️ if you like this project!
108
124
 
125
+ If this project help you reduce time to develop, you can give me a cup of coffee :)
126
+
127
+ [![paypal][paypal-url]][paypal-donate-code]
128
+
109
129
  <!-- MARKDOWN LINKS & IMAGES -->
110
130
  [contributors-shield]: https://img.shields.io/github/contributors/Dandush03/React-Calculator.svg?style=flat-square
111
131
  [contributors-url]: https://github.com/Dandush03/pg_rls/graphs/contributors
@@ -120,4 +140,7 @@ Give a ⭐️ if you like this project!
120
140
  [linkedin-shield2]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555
121
141
  [linkedin-url2]: https://www.linkedin.com/in/daniel-laloush/
122
142
  [hireable]: https://cdn.rawgit.com/hiendv/hireable/master/styles/flat/yes.svg
143
+ [paypal-url]: https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif
144
+ [paypal-donate-code]: https://www.paypal.com/donate?hosted_button_id=QKZFZAMQNC8JL
123
145
  [hireable-url]: https://www.linkedin.com/in/daniel-laloush/
146
+ [donate]: https://img.shields.io/badge/Donate-PayPal-blue.svg
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgRls
4
+ module Test
5
+ # Prepare database for test unit
6
+ module PreparedDatabase
7
+ class << self
8
+ def grant_user_credentials(name: PgRls::SECURE_USERNAME)
9
+ return unless Rails.env.test?
10
+
11
+ PgRls.execute <<-SQL
12
+ GRANT USAGE, SELECT
13
+ ON ALL SEQUENCES IN SCHEMA public
14
+ TO #{name};
15
+ GRANT SELECT, INSERT, UPDATE, DELETE
16
+ ON ALL TABLES IN SCHEMA public
17
+ TO #{name};
18
+ SQL
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRls
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.1.1'
5
5
  end
data/lib/pg_rls.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'active_record'
4
4
  require 'forwardable'
5
5
  require_relative 'pg_rls/version'
6
+ require_relative 'pg_rls/test/prepared_database'
6
7
  require_relative 'pg_rls/schema/statements'
7
8
  require_relative 'pg_rls/tenant'
8
9
  require_relative 'pg_rls/secure_connection'
@@ -11,7 +12,7 @@ require_relative 'pg_rls/multi_tenancy'
11
12
  # PostgreSQL Row Level Security
12
13
  module PgRls
13
14
  class Error < StandardError; end
14
- SECURE_USERNAME = 'app_user'
15
+ SECURE_USERNAME = "#{Rails.env}_app_user".freeze
15
16
 
16
17
  class << self
17
18
  extend Forwardable
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
+ version: 0.0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Laloush
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-11 00:00:00.000000000 Z
11
+ date: 2021-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,7 +24,9 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.2.10
27
- description: Write a longer description or delete this line.
27
+ description: |2
28
+ This gem will help you to integrate PostgreSQL RLS to help you develop a great multitenancy application
29
+ checkout the repository at https://github.com/Dandush03/pg_rls
28
30
  email:
29
31
  - daniel.laloush@influitive.com
30
32
  executables: []
@@ -61,6 +63,7 @@ files:
61
63
  - lib/pg_rls/schema/up_statements.rb
62
64
  - lib/pg_rls/secure_connection.rb
63
65
  - lib/pg_rls/tenant.rb
66
+ - lib/pg_rls/test/prepared_database.rb
64
67
  - lib/pg_rls/version.rb
65
68
  homepage: https://github.com/Dandush03/pg_rls
66
69
  licenses: