rails_sql_prettifier 5.0.3 → 5.0.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: cf8c24bd9ffa08aa300b4c6540027a1e6a2c288dc4661c93834748d445711e42
4
- data.tar.gz: ef7945e5d80df9daff0603f3b87f8ed7c209d35b971d0b1817bf94fa409cde21
3
+ metadata.gz: ba0aedcc17d28557a7bb000e0ed40a926c68d49607336640caa0d1b7fdb8def5
4
+ data.tar.gz: b062509b0ad5b03095d5e5ac8ae8555c463c345e67dc115cab59cc3c1bf4ee43
5
5
  SHA512:
6
- metadata.gz: 3f2790f713dd38d823a78f947a4fa4234a8c4a8e7ad5e799804d7eb9b43d5ecfbd7b82bcefcbb5fc69fd12512d1a686b50056be9a226413d7e90590005f0bf80
7
- data.tar.gz: 817035ebee03c657e04a83b5817ec87a6cb36c19d91d9498b30d31236342a10a88af6d9b760673eed4d2655b36ef20a419e0c00c78c32880423d74b09208546d
6
+ metadata.gz: 48be6e8685ae50b452e3793fa8e05e594debbf08a7b501c57de0a97805104d8afbb8f543366e73e539e28b837c6e86af9a8434d0e7e9b9f249a52853cdc0f092
7
+ data.tar.gz: 6e1aa511179a91313381fa05f16ebc71aef8710a32a580b6d472afce4022aecae99627394e23cdfe392603269843e54a78cbdb7f1d37a083dd7e4d3c5f720b2f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 5.0.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
+ #5.0.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
  # 5.0.3
2
10
  * active record versioning is properly aligned now
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
  #
@@ -103,7 +105,7 @@ end
103
105
  # only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
104
106
  Model.scope.to_niceql
105
107
 
106
- # prettify PG errors if scope runs with any
108
+ # will run prettified sql and hence will properly prettify PG errors if scope runs with any
107
109
  Model.scope_with_err.exec_niceql
108
110
  ```
109
111
 
@@ -157,7 +159,10 @@ end
157
159
  If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
158
160
  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
161
 
160
- ##
162
+ ## Testing
163
+ ```bash
164
+ docker-compose up
165
+ ```
161
166
 
162
167
  ## Contributing
163
168
 
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_5_0
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_5_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 = '5.0.3'
2
+ VERSION = '5.0.5'
3
3
  end
@@ -28,11 +28,13 @@ module RailsSQLPrettifier
28
28
  end
29
29
 
30
30
  module AbstractAdapterLogPrettifier
31
- def log( sql, *args, &block )
31
+ private
32
+ def log( sql, *args, **kwargs, &block )
32
33
  # \n need to be placed because AR log will start with action description + time info.
33
34
  # rescue sql - just to be sure Prettifier wouldn't break production
34
35
  formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
35
- super( formatted_sql, *args, &block )
36
+
37
+ super( formatted_sql, *args, **kwargs, &block )
36
38
  end
37
39
  end
38
40
 
@@ -70,8 +72,8 @@ module RailsSQLPrettifier
70
72
  def configure
71
73
  super
72
74
 
73
- if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
74
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
75
+ if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
76
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
75
77
  end
76
78
 
77
79
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
@@ -80,6 +82,13 @@ module RailsSQLPrettifier
80
82
  end
81
83
  end
82
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
+
83
92
  [::ActiveRecord::Relation,
84
93
  ::Arel::TreeManager,
85
94
  ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
@@ -88,4 +97,5 @@ module RailsSQLPrettifier
88
97
 
89
98
  # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
90
99
  Niceql.singleton_class.prepend( NiceqlExt )
100
+ Niceql.extend(ProtectedEnv)
91
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
 
36
36
  spec.add_dependency "activerecord", "< 6.0"
37
37
 
@@ -39,10 +39,11 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "rake", ">= 12.3.3"
40
40
  spec.add_development_dependency "minitest", "~> 5.0"
41
41
 
42
+ spec.add_development_dependency "awesome_print"
42
43
  spec.add_development_dependency "differ", '~> 0.1'
43
44
  spec.add_development_dependency "pry-byebug", '~> 3.9'
44
45
  spec.add_development_dependency 'sqlite3', '~> 1'
45
46
  spec.add_development_dependency 'pg', '~> 1'
46
47
 
47
- spec.add_development_dependency 'stubberry', '~> 0.1'
48
+ spec.add_development_dependency 'stubberry', '~> 0.2'
48
49
  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: 5.0.3
4
+ version: 5.0.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
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: differ
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +156,14 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0.1'
159
+ version: '0.2'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0.1'
166
+ version: '0.2'
153
167
  description: 'This is an ActiveRecord integration for the SQL prettifier gem niceql. '
154
168
  email:
155
169
  - leshchuk@gmail.com
@@ -164,6 +178,7 @@ files:
164
178
  - ".travis.yml"
165
179
  - CHANGELOG.md
166
180
  - Dockerfile
181
+ - Dockerfile_30
167
182
  - Gemfile
168
183
  - LICENSE.txt
169
184
  - README.md