rails_sql_prettifier 5.0.2 → 5.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/Dockerfile_30 +20 -0
- data/README.md +16 -8
- data/docker-compose.yml +11 -2
- data/lib/rails_sql_prettifier/version.rb +1 -1
- data/lib/rails_sql_prettifier.rb +14 -4
- data/rails_sql_prettifier.gemspec +4 -3
- metadata +23 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba0aedcc17d28557a7bb000e0ed40a926c68d49607336640caa0d1b7fdb8def5
|
4
|
+
data.tar.gz: b062509b0ad5b03095d5e5ac8ae8555c463c345e67dc115cab59cc3c1bf4ee43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48be6e8685ae50b452e3793fa8e05e594debbf08a7b501c57de0a97805104d8afbb8f543366e73e539e28b837c6e86af9a8434d0e7e9b9f249a52853cdc0f092
|
7
|
+
data.tar.gz: 6e1aa511179a91313381fa05f16ebc71aef8710a32a580b6d472afce4022aecae99627394e23cdfe392603269843e54a78cbdb7f1d37a083dd7e4d3c5f720b2f
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
# 5.0.
|
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
|
+
|
9
|
+
# 5.0.3
|
10
|
+
* active record versioning is properly aligned now
|
11
|
+
|
12
|
+
# 5.0.2
|
2
13
|
* Fixed issue with Niceql.configure not configuring anything + test covered
|
3
14
|
|
4
15
|
# 5.0.0
|
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
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
This is an ActiveRecord integration for a niceql gem ( niceql is a small, nice, simple and zero dependency solution for the SQL prettifying in ruby ).
|
4
4
|
|
5
|
-
This gem
|
6
|
-
|
5
|
+
This gem started as a code extraction from niceql version 0.4.x.
|
6
|
+
|
7
|
+
It has versioning aligned to the ActiveRecord versions, niceql prior to 0.5 version had hardcoded logic branches based on ActiveRecord versioning.
|
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 implementations in the error prettifying methods. It will be completely decoupled in the future )
|
7
10
|
|
8
11
|
Any reasonable suggestions are welcome.
|
9
12
|
|
@@ -31,7 +34,7 @@ if whenever you specify versions manually.
|
|
31
34
|
Add this line to your application's Gemfile:
|
32
35
|
|
33
36
|
```ruby
|
34
|
-
gem 'rails_sql_prettifier'
|
37
|
+
gem 'rails_sql_prettifier', '~> X.X.X'
|
35
38
|
```
|
36
39
|
|
37
40
|
And then execute:
|
@@ -48,12 +51,14 @@ Or install it yourself as:
|
|
48
51
|
|
49
52
|
```ruby
|
50
53
|
Niceql.configure do |c|
|
51
|
-
# Setting pg_adapter_with_nicesql to true will
|
54
|
+
# Setting pg_adapter_with_nicesql to true will APPLY formatting SQL queries
|
52
55
|
# before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
|
53
56
|
# if you are using Postgresql as a data source.
|
54
|
-
# BUT do not use it in production until https://github.com/alekseyl/niceql/issues/16 is resolved
|
55
57
|
#
|
56
|
-
#
|
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
|
57
62
|
#
|
58
63
|
# If you need to debug SQL queries in production use exec_niceql
|
59
64
|
#
|
@@ -100,7 +105,7 @@ end
|
|
100
105
|
# only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
|
101
106
|
Model.scope.to_niceql
|
102
107
|
|
103
|
-
# 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
|
104
109
|
Model.scope_with_err.exec_niceql
|
105
110
|
```
|
106
111
|
|
@@ -154,7 +159,10 @@ end
|
|
154
159
|
If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
|
155
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.
|
156
161
|
|
157
|
-
##
|
162
|
+
## Testing
|
163
|
+
```bash
|
164
|
+
docker-compose up
|
165
|
+
```
|
158
166
|
|
159
167
|
## Contributing
|
160
168
|
|
data/docker-compose.yml
CHANGED
@@ -3,8 +3,17 @@ version: "3.7"
|
|
3
3
|
services:
|
4
4
|
test:
|
5
5
|
build: .
|
6
|
-
image:
|
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
|
|
data/lib/rails_sql_prettifier.rb
CHANGED
@@ -28,11 +28,13 @@ module RailsSQLPrettifier
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module AbstractAdapterLogPrettifier
|
31
|
-
|
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
|
-
|
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?(
|
74
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(
|
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,18 +31,19 @@ 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.
|
34
|
+
spec.add_dependency "niceql", '~> 0.6'
|
35
35
|
|
36
|
-
spec.
|
36
|
+
spec.add_dependency "activerecord", "< 6.0"
|
37
37
|
|
38
38
|
spec.add_development_dependency "bundler", ">= 1"
|
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.
|
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.
|
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-
|
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.
|
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.
|
26
|
+
version: '0.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6.0'
|
34
|
-
type: :
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -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.
|
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.
|
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
|
@@ -202,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
217
|
- !ruby/object:Gem::Version
|
203
218
|
version: '0'
|
204
219
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
220
|
+
rubygems_version: 3.1.4
|
206
221
|
signing_key:
|
207
222
|
specification_version: 4
|
208
223
|
summary: This is an ActiveRecord integration for the SQL prettifier gem niceql.
|