rails_sql_prettifier 7.0.2 → 7.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/Dockerfile_30 +20 -0
- data/README.md +11 -8
- data/docker-compose.yml +9 -1
- data/lib/rails_sql_prettifier/version.rb +1 -1
- data/lib/rails_sql_prettifier.rb +15 -7
- data/rails_sql_prettifier.gemspec +3 -2
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdf919f40234cb53ea8a819066c0f83b289a20d25143f130aef38e9145d8c6bb
|
4
|
+
data.tar.gz: 7b137d512642549c1824b50acaaaf4ad123593814316833ac880a49e3cddb195
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1cecf0951a654443dd085c2abf96829af343ea590e9776319cfd9261ad03d5bcd6eb45a65f9c50699a025787ed8c3ca38c574bfd2cee94785f6cad3c252f959
|
7
|
+
data.tar.gz: 2909521fbfc5f49cfe57aae5ffe68a778ebdcaf4a55f725486ead326a2abe2634431ceba0ba736d98bc9ff1340e3b0e647f1b724cc73d9f9bfb3bab1a4d97f0f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
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
|
+
|
5
|
+
#7.0.3
|
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
|
#7.0.2
|
2
10
|
* active record versioning is properly aligned now
|
3
11
|
|
4
12
|
#7.0.0
|
5
|
-
|
6
13
|
* current master branch
|
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
|
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
|
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
|
-
#
|
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
|
|
data/docker-compose.yml
CHANGED
@@ -4,7 +4,15 @@ services:
|
|
4
4
|
test:
|
5
5
|
build: .
|
6
6
|
image: niceql
|
7
|
-
command: service postgresql start && rake test
|
7
|
+
command: /bin/bash -c 'service postgresql start && rake test'
|
8
8
|
volumes:
|
9
9
|
- '.:/app'
|
10
10
|
|
11
|
+
test_3_0:
|
12
|
+
build:
|
13
|
+
context: .
|
14
|
+
dockerfile: Dockerfile_30
|
15
|
+
image: niceql_3_0
|
16
|
+
command: /bin/bash -c 'service postgresql start && rake test'
|
17
|
+
volumes:
|
18
|
+
- '.:/app'
|
data/lib/rails_sql_prettifier.rb
CHANGED
@@ -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
|
@@ -28,11 +27,13 @@ module RailsSQLPrettifier
|
|
28
27
|
end
|
29
28
|
|
30
29
|
module AbstractAdapterLogPrettifier
|
31
|
-
|
30
|
+
private
|
31
|
+
def log( sql, *args, **kwargs, &block )
|
32
32
|
# \n need to be placed because AR log will start with action description + time info.
|
33
33
|
# rescue sql - just to be sure Prettifier wouldn't break production
|
34
34
|
formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
|
35
|
-
|
35
|
+
|
36
|
+
super( formatted_sql, *args, **kwargs, &block )
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -53,7 +54,6 @@ module RailsSQLPrettifier
|
|
53
54
|
:prettify_pg_errors
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
57
|
def ar_using_pg_adapter?
|
58
58
|
ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
|
59
59
|
end
|
@@ -70,8 +70,8 @@ module RailsSQLPrettifier
|
|
70
70
|
def configure
|
71
71
|
super
|
72
72
|
|
73
|
-
if config.pg_adapter_with_nicesql && defined?(
|
74
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(
|
73
|
+
if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
|
74
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
|
75
75
|
end
|
76
76
|
|
77
77
|
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
|
@@ -80,6 +80,13 @@ module RailsSQLPrettifier
|
|
80
80
|
end
|
81
81
|
end
|
82
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
|
+
|
83
90
|
[::ActiveRecord::Relation,
|
84
91
|
::Arel::TreeManager,
|
85
92
|
::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
|
@@ -88,4 +95,5 @@ module RailsSQLPrettifier
|
|
88
95
|
|
89
96
|
# we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
|
90
97
|
Niceql.singleton_class.prepend( NiceqlExt )
|
91
|
-
|
98
|
+
Niceql.extend(ProtectedEnv)
|
99
|
+
end
|
@@ -31,17 +31,18 @@ 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
|
spec.add_dependency "activerecord", '>= 7'
|
36
36
|
|
37
37
|
spec.add_development_dependency "bundler", ">= 1"
|
38
38
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
39
39
|
spec.add_development_dependency "minitest", "~> 5.0"
|
40
40
|
|
41
|
+
spec.add_development_dependency "awesome_print"
|
41
42
|
spec.add_development_dependency "differ", '~> 0.1'
|
42
43
|
spec.add_development_dependency "pry-byebug", '~> 3.9'
|
43
44
|
spec.add_development_dependency 'sqlite3', '~> 1'
|
44
45
|
spec.add_development_dependency 'pg', '~> 1'
|
45
46
|
|
46
|
-
spec.add_development_dependency 'stubberry', '~> 0.
|
47
|
+
spec.add_development_dependency 'stubberry', '~> 0.2'
|
47
48
|
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: 7.0.
|
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-
|
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
|
@@ -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
|
@@ -163,6 +177,7 @@ files:
|
|
163
177
|
- ".travis.yml"
|
164
178
|
- CHANGELOG.md
|
165
179
|
- Dockerfile
|
180
|
+
- Dockerfile_30
|
166
181
|
- Gemfile
|
167
182
|
- LICENSE.txt
|
168
183
|
- README.md
|