rails_sql_prettifier 7.0.3 → 7.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e25116da08165fe68232d88629379f8e8cb48c503ad73926119d1906ee0a45d6
4
- data.tar.gz: 3efe5e251b908df04d3e551c2a7318405cbd9392d818652db85cd73165fa4a9f
3
+ metadata.gz: 178b6c12be831f4a33836aea1ce14e8f6490420f687de6cba3545b8363a71bb6
4
+ data.tar.gz: fc2c6e85fc32dfa3bcc941acf31c229c401cf35458e285f2ef161ee76b22f79b
5
5
  SHA512:
6
- metadata.gz: 78ea21d51cd7cad7b59599979a9529f7ca4173709b758b3ab4eecf2aea49e53644d7399ee303ef42d0789454a88abec6a422b9ec6b6108bc1251e15fb6216d18
7
- data.tar.gz: 1958bdd7757d0d51d4b54e3d8eef556c4b42f7a18ac914677c7f8130c76c86a40627c8c251bbdbe9a6394c1f224b4aa53401d9968410fec49c89098354887153
6
+ metadata.gz: c5be4b4ecc5dcc39e495313cd859b41ee30ef21f2cc99508ec5c339b35ea2886afff4f7e0404d9a1b137fef41df1b7faf82f3d23bbe98c2e6bdb282512340a27
7
+ data.tar.gz: 558975a592a45895d2f64d6867a80c04658109dff8d32480f8502ff97a7b46e78fd0d3d598bde331f9385ddc2bd8161a0bef574c3374719c6a2a8cfed4a64bc7
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ bundler-cache: true # 'bundle install' and cache gems
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Run tests
23
+ run: service postgresql start && bundle exec rake test
@@ -0,0 +1,17 @@
1
+ name: RuboCop
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ bundler-cache: true # 'bundle install' and cache
16
+ - name: Run RuboCop
17
+ run: bundle exec rubocop --parallel
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 7.0.5
2
+ * Fixed tests
3
+ * Restructured code properly
4
+ * Fixed issue with exec_niceql over relation with error, now error will be prettified properly
5
+
6
+ # 7.0.4
7
+ * pg_adapter_with_nicesql setting will not be set to action for protected_env
8
+ * niceql version set to ~> 0.6 (fixed https://github.com/alekseyl/niceql/issues/16 !)
9
+
1
10
  #7.0.3
2
11
  * fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
3
12
  * adding support for multiple ruby versions testing using docker-compose
data/Dockerfile CHANGED
@@ -5,13 +5,13 @@ RUN apt-get update && apt-get -y install lsb-release
5
5
  #
6
6
  RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
7
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
8
+ apt-get update && apt-get -y install postgresql postgresql-client-14
9
9
 
10
- RUN sh -c 'echo "local all all trust" > /etc/postgresql/14/main/pg_hba.conf' && \
10
+ RUN sh -c 'echo "local all all trust" > /etc/postgresql/$(ls /etc/postgresql)/main/pg_hba.conf' && \
11
11
  service postgresql start && \
12
12
  psql -U postgres -c 'CREATE DATABASE "niceql-test"'
13
13
 
14
- RUN gem install bundler
14
+ RUN gem install bundler -v 2.4.22
15
15
 
16
16
  COPY lib/rails_sql_prettifier/version.rb /app/lib/rails_sql_prettifier/version.rb
17
17
  COPY rails_sql_prettifier.gemspec /app/
data/Dockerfile_30 CHANGED
@@ -5,13 +5,13 @@ RUN apt-get update && apt-get -y install lsb-release
5
5
  #
6
6
  RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
7
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
8
+ apt-get update && apt-get -y install postgresql postgresql-client-14
9
9
 
10
- RUN sh -c 'echo "local all all trust" > /etc/postgresql/14/main/pg_hba.conf' && \
10
+ RUN sh -c 'echo "local all all trust" > /etc/postgresql/$(ls /etc/postgresql)/main/pg_hba.conf' && \
11
11
  service postgresql start && \
12
12
  psql -U postgres -c 'CREATE DATABASE "niceql-test"'
13
13
 
14
- RUN gem install bundler
14
+ RUN gem install bundler -v 2.4.22
15
15
 
16
16
  COPY lib/rails_sql_prettifier/version.rb /app/lib/rails_sql_prettifier/version.rb
17
17
  COPY rails_sql_prettifier.gemspec /app/
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,5 +1,5 @@
1
1
  Niceql.configure do |c|
2
- # You can adjust pg_adapter in prooduction at your own risk!
2
+ # You can adjust pg_adapter in production at your own risk!
3
3
  # If you need it in production use exec_niceql
4
4
  # default: false
5
5
  # c.pg_adapter_with_nicesql = Rails.env.development?
@@ -8,4 +8,4 @@ Niceql.configure do |c|
8
8
  # c.indentation_base = 2
9
9
  # c.open_bracket_is_newliner = false
10
10
  # c.prettify_active_record_log_output = false
11
- end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+ module AbstractAdapterLogPrettifier
5
+ private
6
+ def log( sql, *args, **kwargs, &block )
7
+ # \n need to be placed because AR log will start with action description + time info.
8
+ # rescue sql - just to be sure Prettifier wouldn't break production
9
+ formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
10
+
11
+ super( formatted_sql, *args, **kwargs, &block )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+
5
+ module ArExtentions
6
+ def exec_niceql(reraise = false)
7
+ connection.execute( to_niceql )
8
+ rescue => e
9
+ puts Niceql::Prettifier.prettify_pg_err( e.message, to_niceql )
10
+ raise if reraise
11
+ end
12
+
13
+ def to_niceql
14
+ Niceql::Prettifier.prettify_sql(to_sql, false)
15
+ end
16
+
17
+ def niceql( colorize = true )
18
+ puts Niceql::Prettifier.prettify_sql( to_sql, colorize )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+ module NiceQLConfigExt
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :pg_adapter_with_nicesql,
9
+ :prettify_active_record_log_output,
10
+ :prettify_pg_errors
11
+
12
+ # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
13
+ Niceql.singleton_class.prepend(Configure)
14
+ end
15
+
16
+ def ar_using_pg_adapter?
17
+ ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
18
+ end
19
+
20
+ def initialize
21
+ super
22
+ self.pg_adapter_with_nicesql = false
23
+ self.prettify_active_record_log_output = false
24
+ self.prettify_pg_errors = ar_using_pg_adapter?
25
+ end
26
+
27
+ module Configure
28
+ def configure
29
+ super
30
+
31
+ if config.pg_adapter_with_nicesql &&
32
+ defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
33
+
34
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
35
+ end
36
+
37
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(AbstractAdapterLogPrettifier) if config.prettify_active_record_log_output
38
+
39
+ ::ActiveRecord::StatementInvalid.include(NiceqlError) if config.prettify_pg_errors && config.ar_using_pg_adapter?
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module RailsSQLPrettifier
3
+ module NiceqlError
4
+ def to_s
5
+ # older rails version do not provide sql as a standalone query, instead they
6
+ # deliver joined message, and try(:sql) will set prettify_err with nil in that case
7
+ Niceql.config.prettify_pg_errors ? Niceql::Prettifier.prettify_err(super, try(:sql) ) : super
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+ module PostgresAdapterNiceQL
5
+ def exec_query(sql, *args, **kwargs, &block)
6
+ # replacing sql with prettified sql, that's all
7
+ super( Niceql::Prettifier.prettify_sql(sql, false), *args, **kwargs, &block )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+
5
+ module ProtectedEnv
6
+ def protected_env?
7
+ ActiveRecord::Base.connection.migration_context.protected_environment? ||
8
+ defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '7.0.3'
2
+ VERSION = '7.0.5'
3
3
  end
@@ -1,92 +1,19 @@
1
1
  require "rails_sql_prettifier/version"
2
+ require "rails_sql_prettifier/abstract_adapter_log_prettifier"
3
+ require "rails_sql_prettifier/ar_extensions"
4
+ require "rails_sql_prettifier/niceql_error"
5
+ require "rails_sql_prettifier/nice_ql_config_ext"
6
+ require "rails_sql_prettifier/postgres_adapter_nice_ql"
7
+ require "rails_sql_prettifier/protected_env"
8
+
2
9
  require 'active_record'
3
10
  require "niceql"
4
11
 
5
-
6
12
  module RailsSQLPrettifier
13
+ ::ActiveRecord::Relation.include ArExtentions
14
+ ::Arel::TreeManager.include ArExtentions
15
+ ::Arel::Nodes::Node.include ArExtentions
7
16
 
8
- module ArExtentions
9
- def exec_niceql
10
- connection.execute( to_niceql )
11
- end
12
-
13
- def to_niceql
14
- Niceql::Prettifier.prettify_sql(to_sql, false)
15
- end
16
-
17
- def niceql( colorize = true )
18
- puts Niceql::Prettifier.prettify_sql( to_sql, colorize )
19
- end
20
-
21
- end
22
-
23
- module PostgresAdapterNiceQL
24
- def exec_query(sql, name = "SQL", binds = [], prepare: false)
25
- # replacing sql with prettified sql, thats all
26
- super( Niceql::Prettifier.prettify_sql(sql, false), name, binds, prepare: prepare )
27
- end
28
- end
29
-
30
- module AbstractAdapterLogPrettifier
31
- private
32
- def log( sql, *args, **kwargs, &block )
33
- # \n need to be placed because AR log will start with action description + time info.
34
- # rescue sql - just to be sure Prettifier wouldn't break production
35
- formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
36
-
37
- super( formatted_sql, *args, **kwargs, &block )
38
- end
39
- end
40
-
41
- module ErrorExt
42
- def to_s
43
- # older rails version do not provide sql as a standalone query, instead they
44
- # deliver joined message
45
- Niceql.config.prettify_pg_errors ? Niceql::Prettifier.prettify_err(super, try(:sql) ) : super
46
- end
47
- end
48
-
49
- module NiceQLConfigExt
50
- extend ActiveSupport::Concern
51
-
52
- included do
53
- attr_accessor :pg_adapter_with_nicesql,
54
- :prettify_active_record_log_output,
55
- :prettify_pg_errors
56
- end
57
-
58
- def ar_using_pg_adapter?
59
- ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
60
- end
61
-
62
- def initialize
63
- super
64
- self.pg_adapter_with_nicesql = false
65
- self.prettify_active_record_log_output = false
66
- self.prettify_pg_errors = ar_using_pg_adapter?
67
- end
68
- end
69
-
70
- module NiceqlExt
71
- def configure
72
- super
73
-
74
- if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
75
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
76
- end
77
-
78
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
79
-
80
- ::ActiveRecord::StatementInvalid.include( RailsSQLPrettifier::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
81
- end
82
- end
83
-
84
- [::ActiveRecord::Relation,
85
- ::Arel::TreeManager,
86
- ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
87
-
88
- Niceql::NiceQLConfig.include( NiceQLConfigExt )
89
-
90
- # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
91
- Niceql.singleton_class.prepend( NiceqlExt )
17
+ Niceql::NiceQLConfig.include(NiceQLConfigExt)
18
+ Niceql.extend(ProtectedEnv)
92
19
  end
@@ -30,9 +30,10 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.required_ruby_version = '>= 2.4'
34
- spec.add_dependency "niceql", '~> 0.5'
35
- spec.add_dependency "activerecord", '>= 7'
33
+ # for rails 7 you cannot use ruby below 2.7
34
+ spec.required_ruby_version = '>= 2.7'
35
+ spec.add_dependency "niceql", '~> 0.6'
36
+ spec.add_dependency "activerecord", '>= 7', '< 8'
36
37
 
37
38
  spec.add_development_dependency "bundler", ">= 1"
38
39
  spec.add_development_dependency "rake", ">= 12.3.3"
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.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-19 00:00:00.000000000 Z
11
+ date: 2025-02-22 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
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '7'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '8'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '7'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '8'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -171,10 +177,12 @@ executables: []
171
177
  extensions: []
172
178
  extra_rdoc_files: []
173
179
  files:
180
+ - ".github/dependabot.yml"
181
+ - ".github/workflows/ci.yml"
182
+ - ".github/workflows/rubocop.yml"
174
183
  - ".gitignore"
175
184
  - ".ruby-gemset"
176
185
  - ".ruby-version"
177
- - ".travis.yml"
178
186
  - CHANGELOG.md
179
187
  - Dockerfile
180
188
  - Dockerfile_30
@@ -193,6 +201,12 @@ files:
193
201
  - lib/generators/niceql/install_generator.rb
194
202
  - lib/generators/templates/niceql_initializer.rb
195
203
  - lib/rails_sql_prettifier.rb
204
+ - lib/rails_sql_prettifier/abstract_adapter_log_prettifier.rb
205
+ - lib/rails_sql_prettifier/ar_extensions.rb
206
+ - lib/rails_sql_prettifier/nice_ql_config_ext.rb
207
+ - lib/rails_sql_prettifier/niceql_error.rb
208
+ - lib/rails_sql_prettifier/postgres_adapter_nice_ql.rb
209
+ - lib/rails_sql_prettifier/protected_env.rb
196
210
  - lib/rails_sql_prettifier/version.rb
197
211
  - rails_sql_prettifier.gemspec
198
212
  - to_niceql.png
@@ -209,14 +223,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
223
  requirements:
210
224
  - - ">="
211
225
  - !ruby/object:Gem::Version
212
- version: '2.4'
226
+ version: '2.7'
213
227
  required_rubygems_version: !ruby/object:Gem::Requirement
214
228
  requirements:
215
229
  - - ">="
216
230
  - !ruby/object:Gem::Version
217
231
  version: '0'
218
232
  requirements: []
219
- rubygems_version: 3.1.4
233
+ rubygems_version: 3.3.26
220
234
  signing_key:
221
235
  specification_version: 4
222
236
  summary: This is an ActiveRecord integration for the SQL prettifier gem niceql.
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4
5
- - 2.5
6
- - 2.3
7
- - 2.6