rails_sql_prettifier 7.0.3 → 7.0.4

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: e25116da08165fe68232d88629379f8e8cb48c503ad73926119d1906ee0a45d6
4
- data.tar.gz: 3efe5e251b908df04d3e551c2a7318405cbd9392d818652db85cd73165fa4a9f
3
+ metadata.gz: fdf919f40234cb53ea8a819066c0f83b289a20d25143f130aef38e9145d8c6bb
4
+ data.tar.gz: 7b137d512642549c1824b50acaaaf4ad123593814316833ac880a49e3cddb195
5
5
  SHA512:
6
- metadata.gz: 78ea21d51cd7cad7b59599979a9529f7ca4173709b758b3ab4eecf2aea49e53644d7399ee303ef42d0789454a88abec6a422b9ec6b6108bc1251e15fb6216d18
7
- data.tar.gz: 1958bdd7757d0d51d4b54e3d8eef556c4b42f7a18ac914677c7f8130c76c86a40627c8c251bbdbe9a6394c1f224b4aa53401d9968410fec49c89098354887153
6
+ metadata.gz: a1cecf0951a654443dd085c2abf96829af343ea590e9776319cfd9261ad03d5bcd6eb45a65f9c50699a025787ed8c3ca38c574bfd2cee94785f6cad3c252f959
7
+ data.tar.gz: 2909521fbfc5f49cfe57aae5ffe68a778ebdcaf4a55f725486ead326a2abe2634431ceba0ba736d98bc9ff1340e3b0e647f1b724cc73d9f9bfb3bab1a4d97f0f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 7.0.4
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
  #7.0.3
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
@@ -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
  #
@@ -101,7 +103,7 @@ end
101
103
  # only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
102
104
  Model.scope.to_niceql
103
105
 
104
- # 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
105
107
  Model.scope_with_err.exec_niceql
106
108
  ```
107
109
 
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '7.0.3'
2
+ VERSION = '7.0.4'
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
@@ -71,8 +70,8 @@ module RailsSQLPrettifier
71
70
  def configure
72
71
  super
73
72
 
74
- if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
75
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
73
+ if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
74
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
76
75
  end
77
76
 
78
77
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
@@ -81,6 +80,13 @@ module RailsSQLPrettifier
81
80
  end
82
81
  end
83
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
+
84
90
  [::ActiveRecord::Relation,
85
91
  ::Arel::TreeManager,
86
92
  ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
@@ -89,4 +95,5 @@ module RailsSQLPrettifier
89
95
 
90
96
  # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
91
97
  Niceql.singleton_class.prepend( NiceqlExt )
92
- end
98
+ Niceql.extend(ProtectedEnv)
99
+ 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", '>= 7'
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: 7.0.3
4
+ version: 7.0.4
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