rails_sql_prettifier 6.0.5 → 6.0.6

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: fd0305095915e20ebc2a5b5529c0681f4e82795c1dd748764185c2aeef922298
4
- data.tar.gz: 286a20bb4acc2213dd4d8fe3e97f48977857360d2ab65a6b03f8d017f4add700
3
+ metadata.gz: f1b2fae31052f2d4e36efb1c866a1f69e0a6d1ca94757c17bcd4edf82715fdcb
4
+ data.tar.gz: a981254b8b0fe7187c5131a5dedbde563e06b631dbf775f7232c388eb9a92bec
5
5
  SHA512:
6
- metadata.gz: a3010b72fd84d20a273ae11880a624a2758158354249abd1534020810d94f20297a8d73306ed36b31ad69fe24a9367931e59cc4b07fe90b9d57a9743122c2bef
7
- data.tar.gz: 2c06865138f0a7fe2c407673f567b4c1721c7ac799598ec0252682d995808c7bfd26fe11236895f9d7749768e48dbebf4e08517a7f68ae7196331d9c31a89d89
6
+ metadata.gz: ba0edebb77ea3050622d298f44b3cfeeb8bb7837214e6fc663e9da407fffc0145c35b77abbb8b46b063da4864726253fad7208a6c5bc29bdfbca8e231583207a
7
+ data.tar.gz: 7c52e3a94ba9540d05b1b472ecdb492315efde99250783e5a17882ee53285217704044e3a1799592f58d0302969e2c5bc5ec1d233419fa8629204052a2cf449c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 6.0.6
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
+
1
5
  #6.0.5
2
6
  * fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
3
7
  * adding support for multiple ruby versions testing using docker-compose
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
 
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '6.0.5'
2
+ VERSION = '6.0.6'
3
3
  end
@@ -72,8 +72,8 @@ module RailsSQLPrettifier
72
72
  def configure
73
73
  super
74
74
 
75
- if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
76
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
75
+ if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
76
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
77
77
  end
78
78
 
79
79
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
@@ -82,6 +82,13 @@ module RailsSQLPrettifier
82
82
  end
83
83
  end
84
84
 
85
+ module ProtectedEnv
86
+ def protected_env?
87
+ ActiveRecord::Base.connection.migration_context.protected_environment? ||
88
+ defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
89
+ end
90
+ end
91
+
85
92
  [::ActiveRecord::Relation,
86
93
  ::Arel::TreeManager,
87
94
  ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
@@ -90,4 +97,5 @@ module RailsSQLPrettifier
90
97
 
91
98
  # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
92
99
  Niceql.singleton_class.prepend( NiceqlExt )
100
+ Niceql.extend(ProtectedEnv)
93
101
  end
@@ -31,7 +31,7 @@ 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.0', '< 6.1'
36
36
 
37
37
  spec.add_development_dependency "bundler", ">= 1"
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.0.5
4
+ version: 6.0.6
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-19 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