rails_sql_prettifier 6.1.3 → 6.1.5

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: 27c2c94ce703f039972dc6a71d7141875b70fbe8ee4c069ca6c0fd0e0a61c8b0
4
- data.tar.gz: d4065bbe16258c466c12906f636a606477f35659a10c71ec504a0044d672b24b
3
+ metadata.gz: 8df9f5495c84355c3c6a09a4365848d9dfd9e96705b2bd108123d57a4b202b7e
4
+ data.tar.gz: '02848ff4f8e3d3413e94f48fbc2c7b57077007231ba262f707e4ee56567eefdd'
5
5
  SHA512:
6
- metadata.gz: cfa6e69b57fdf10fbc5508031805423683947bbbd3c7f68cb4c749db131a6e45dc2e58f653fd59c92244cb6e93b42fd277fd63c7451a902814de16b57f1576b0
7
- data.tar.gz: 1fc269b0db15097276a0c73dbe7e96f4e796983a4eded9025db72d08f97aeb06929b5ed61759144f598a2bc29682f25c65cffbef9d47c16e93318ab55b488b2a
6
+ metadata.gz: 936d928a81e4d239bea1133ffc0e962e99f982398aaa5483ad1fc2b90d2bf09b891f1d8baf64cc5a16bdd5acb4250dd0f60c552a671b94ec5c8a0b316b60dd51
7
+ data.tar.gz: b4d450f3216791ccc8f7888ad5324dd94248724f52c6043f561fedd1eecfa440541a6d0a8845fe0c394b7fbf2a3ed419e6a76cda0acce1aa0edcf444445403cf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 6.1.5
2
+ * pg_adapter_with_nicesql setting will not be set to action for protected_env
3
+ * niceql version set to ~> 0.6 (fixed https://github.com/alekseyl/niceql/issues/16 !)
4
+
5
+ # 6.1.4
6
+ * fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
7
+ * adding support for multiple ruby versions testing using docker-compose
8
+
1
9
  # 6.1.3
2
10
  * Now AR is a dependency not a development dependency
3
11
 
data/Dockerfile_30 ADDED
@@ -0,0 +1,20 @@
1
+ FROM ruby:3.0.3-bullseye
2
+
3
+ WORKDIR /app
4
+ RUN apt-get update && apt-get -y install lsb-release
5
+ #
6
+ RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
7
+ sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
8
+ apt-get update && apt-get -y install postgresql postgresql-client-12
9
+
10
+ RUN sh -c 'echo "local all all trust" > /etc/postgresql/14/main/pg_hba.conf' && \
11
+ service postgresql start && \
12
+ psql -U postgres -c 'CREATE DATABASE "niceql-test"'
13
+
14
+ RUN gem install bundler
15
+
16
+ COPY lib/rails_sql_prettifier/version.rb /app/lib/rails_sql_prettifier/version.rb
17
+ COPY rails_sql_prettifier.gemspec /app/
18
+ COPY Gemfil* /app/
19
+ #
20
+ RUN bundle install
data/README.md CHANGED
@@ -6,7 +6,7 @@ This gem started as a code extraction from niceql version 0.4.x.
6
6
 
7
7
  It has versioning aligned to the ActiveRecord versions, niceql prior to 0.5 version had hardcoded logic branches based on ActiveRecord versioning.
8
8
 
9
- That is hard to maintain and hard to test, and also coupling with AR is breaking the original idea of the niceql to be a dependentless solution, so now the niceql is a completely railsfree gem yeay! ( It still has some some checks related to AR implemetations in the error prettifying methods. It will be completely decoupled in the future )
9
+ That is hard to maintain and hard to test, and also coupling with AR is breaking the original idea of the niceql to be a dependentless solution, so now the niceql is a completely railsfree gem yeay! ( It still has some some checks related to AR implementations in the error prettifying methods. It will be completely decoupled in the future )
10
10
 
11
11
  Any reasonable suggestions are welcome.
12
12
 
@@ -51,12 +51,14 @@ Or install it yourself as:
51
51
 
52
52
  ```ruby
53
53
  Niceql.configure do |c|
54
- # Setting pg_adapter_with_nicesql to true will force formatting SQL queries
54
+ # Setting pg_adapter_with_nicesql to true will APPLY formatting SQL queries
55
55
  # before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
56
56
  # if you are using Postgresql as a data source.
57
- # BUT do not use it in production until https://github.com/alekseyl/niceql/issues/16 is resolved
58
57
  #
59
- # You can adjust pg_adapter in production but do it at your own risk!
58
+ # BUT even though https://github.com/alekseyl/niceql/issues/16 is resolved,
59
+ # there could be other potentially uncovered bugs so its better not to
60
+ # adjust pg_adapter in production, currently there is an additional blocker for that module ProtectedEnv
61
+ # its will not allow patching PGAdapter for other than test/development envs
60
62
  #
61
63
  # If you need to debug SQL queries in production use exec_niceql
62
64
  #
@@ -94,8 +96,6 @@ end
94
96
 
95
97
  ## Usage
96
98
 
97
- ### With ActiveRecord
98
-
99
99
  ```ruby
100
100
  # puts colorized and formatted corresponding SQL query
101
101
  Model.scope.niceql
@@ -103,7 +103,7 @@ end
103
103
  # only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
104
104
  Model.scope.to_niceql
105
105
 
106
- # prettify PG errors if scope runs with any
106
+ # will run prettified sql and hence will properly prettify PG errors if scope runs with any
107
107
  Model.scope_with_err.exec_niceql
108
108
  ```
109
109
 
@@ -157,7 +157,10 @@ end
157
157
  If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
158
158
  Current colors were selected with dark and white console themes in mind, so a niceql colorization works good for dark, and good enough for white.
159
159
 
160
- ##
160
+ ## Testing
161
+ ```bash
162
+ docker-compose up
163
+ ```
161
164
 
162
165
  ## Contributing
163
166
 
data/docker-compose.yml CHANGED
@@ -3,8 +3,17 @@ version: "3.7"
3
3
  services:
4
4
  test:
5
5
  build: .
6
- image: niceql
7
- command: service postgresql start && rake test
6
+ image: rsp_6_1
7
+ command: /bin/bash -c 'service postgresql start && rake test'
8
+ volumes:
9
+ - '.:/app'
10
+
11
+ test_3_0:
12
+ build:
13
+ context: .
14
+ dockerfile: Dockerfile_30
15
+ image: rsp_6_1_3_0
16
+ command: /bin/bash -c 'service postgresql start && rake test'
8
17
  volumes:
9
18
  - '.:/app'
10
19
 
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '6.1.3'
2
+ VERSION = '6.1.5'
3
3
  end
@@ -2,7 +2,6 @@ require "rails_sql_prettifier/version"
2
2
  require 'active_record'
3
3
  require "niceql"
4
4
 
5
-
6
5
  module RailsSQLPrettifier
7
6
 
8
7
  module ArExtentions
@@ -28,11 +27,13 @@ module RailsSQLPrettifier
28
27
  end
29
28
 
30
29
  module AbstractAdapterLogPrettifier
31
- def log( sql, *args, &block )
30
+ private
31
+ def log( sql, *args, **kwargs, &block )
32
32
  # \n need to be placed because AR log will start with action description + time info.
33
33
  # rescue sql - just to be sure Prettifier wouldn't break production
34
34
  formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
35
- super( formatted_sql, *args, &block )
35
+
36
+ super( formatted_sql, *args, **kwargs, &block )
36
37
  end
37
38
  end
38
39
 
@@ -53,7 +54,6 @@ module RailsSQLPrettifier
53
54
  :prettify_pg_errors
54
55
  end
55
56
 
56
-
57
57
  def ar_using_pg_adapter?
58
58
  ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
59
59
  end
@@ -70,8 +70,8 @@ module RailsSQLPrettifier
70
70
  def configure
71
71
  super
72
72
 
73
- if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
74
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
73
+ if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
74
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
75
75
  end
76
76
 
77
77
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
@@ -80,6 +80,13 @@ module RailsSQLPrettifier
80
80
  end
81
81
  end
82
82
 
83
+ module ProtectedEnv
84
+ def protected_env?
85
+ ActiveRecord::Base.connection.migration_context.protected_environment? ||
86
+ defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
87
+ end
88
+ end
89
+
83
90
  [::ActiveRecord::Relation,
84
91
  ::Arel::TreeManager,
85
92
  ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
@@ -88,4 +95,5 @@ module RailsSQLPrettifier
88
95
 
89
96
  # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
90
97
  Niceql.singleton_class.prepend( NiceqlExt )
91
- end
98
+ Niceql.extend(ProtectedEnv)
99
+ end
@@ -31,17 +31,18 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.required_ruby_version = '>= 2.4'
34
- spec.add_dependency "niceql", '~> 0.5'
34
+ spec.add_dependency "niceql", '~> 0.6'
35
35
  spec.add_dependency "activerecord", '>= 6.1', '< 7'
36
36
 
37
37
  spec.add_development_dependency "bundler", ">= 1"
38
38
  spec.add_development_dependency "rake", ">= 12.3.3"
39
39
  spec.add_development_dependency "minitest", "~> 5.0"
40
40
 
41
+ spec.add_development_dependency "awesome_print"
41
42
  spec.add_development_dependency "differ", '~> 0.1'
42
43
  spec.add_development_dependency "pry-byebug", '~> 3.9'
43
44
  spec.add_development_dependency 'sqlite3', '~> 1'
44
45
  spec.add_development_dependency 'pg', '~> 1'
45
46
 
46
- spec.add_development_dependency 'stubberry', '~> 0.1'
47
+ spec.add_development_dependency 'stubberry', '~> 0.2'
47
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_sql_prettifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.3
4
+ version: 6.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-09 00:00:00.000000000 Z
11
+ date: 2022-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: niceql
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '5.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: awesome_print
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: differ
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -148,14 +162,14 @@ dependencies:
148
162
  requirements:
149
163
  - - "~>"
150
164
  - !ruby/object:Gem::Version
151
- version: '0.1'
165
+ version: '0.2'
152
166
  type: :development
153
167
  prerelease: false
154
168
  version_requirements: !ruby/object:Gem::Requirement
155
169
  requirements:
156
170
  - - "~>"
157
171
  - !ruby/object:Gem::Version
158
- version: '0.1'
172
+ version: '0.2'
159
173
  description: 'This is an ActiveRecord integration for the SQL prettifier gem niceql. '
160
174
  email:
161
175
  - leshchuk@gmail.com
@@ -170,6 +184,7 @@ files:
170
184
  - ".travis.yml"
171
185
  - CHANGELOG.md
172
186
  - Dockerfile
187
+ - Dockerfile_30
173
188
  - Gemfile
174
189
  - LICENSE.txt
175
190
  - README.md