rails_spotlight 0.1.6 → 0.1.7
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 507c2c676db5d30d6af1ec0f505e067f16c53514dfd875cd4554041304d95b87
|
4
|
+
data.tar.gz: 8c990b6ec150e2a6c9e7b8e0c581d5b1e74987e5502907e847218a78d6324103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c36b1e95facd5d437c4685a7ba66a02e45eaf152d8e4fc607468fffef5fad8d7fb9c15ed1b760feaa1501b1b2c8a27bd61166917083da90ccb5cf64529530a6c
|
7
|
+
data.tar.gz: d1439a47bedd079561dcecb4a8f1f8cde964eea6555da2dc0e16e330bac2b89abc9e0f90a2a499bf50c1939e1b1e64a0622209a14affa1d951abb76ad4c9732a
|
data/README.md
CHANGED
@@ -48,3 +48,6 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
48
48
|
## Code of Conduct
|
49
49
|
|
50
50
|
Everyone interacting in the RailsSpotlight project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pniemczyk/rails_spotlight/blob/master/CODE_OF_CONDUCT.md).
|
51
|
+
|
52
|
+
|
53
|
+
check https://github.com/alexrudall/ruby-openai
|
@@ -7,26 +7,31 @@ module RailsSpotlight
|
|
7
7
|
module Handlers
|
8
8
|
class SqlActionHandler < BaseActionHandler
|
9
9
|
def execute
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
else
|
17
|
-
ActiveSupport::Notifications.subscribed(method(:logger), 'sql.active_record') do
|
18
|
-
transaction
|
19
|
-
end
|
10
|
+
validate_project!
|
11
|
+
return transaction unless ActiveSupport.const_defined?('ExecutionContext')
|
12
|
+
|
13
|
+
ActiveSupport::ExecutionContext.set(rails_spotlight: request_id) do
|
14
|
+
transaction
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
18
|
private
|
24
19
|
|
20
|
+
def validate_project!
|
21
|
+
Rails.logger.warn required_projects
|
22
|
+
return if required_projects.blank?
|
23
|
+
return if required_projects.include?(::RailsSpotlight::Support::Project.instance.name)
|
24
|
+
|
25
|
+
raise UnprocessableEntity, "Check your connetction settings the current query is not allowed to be executed on the #{::RailsSpotlight::Support::Project.instance.name} project"
|
26
|
+
end
|
27
|
+
|
25
28
|
def transaction
|
26
29
|
ActiveRecord::Base.transaction do
|
27
|
-
begin
|
28
|
-
|
29
|
-
|
30
|
+
begin # rubocop:disable Style/RedundantBegin
|
31
|
+
ActiveSupport::Notifications.subscribed(method(:logger), 'sql.active_record', monotonic: true) do
|
32
|
+
run
|
33
|
+
end
|
34
|
+
rescue => e # rubocop:disable Style/RescueStandardError
|
30
35
|
self.error = e
|
31
36
|
ensure
|
32
37
|
raise ActiveRecord::Rollback unless force_execution?
|
@@ -34,14 +39,25 @@ module RailsSpotlight
|
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
def run
|
43
|
+
return self.result = ActiveRecord::Base.connection.exec_query(query) if connection_options.blank? || !ActiveRecord::Base.respond_to?(:connects_to)
|
44
|
+
|
45
|
+
connections = ActiveRecord::Base.connects_to(**connection_options)
|
46
|
+
|
47
|
+
adapter = connections.find { |c| c.role == use['role'] && c.shard.to_s == use['shard'] }
|
48
|
+
raise UnprocessableEntity, "Connection not found for role: `#{use["role"]}` and shard: `#{use["shard"]}`" if adapter.blank?
|
49
|
+
|
50
|
+
self.result = adapter.connection.exec_query(query)
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_accessor :result, :error
|
39
54
|
|
40
55
|
def json_response_body
|
41
56
|
{
|
57
|
+
query: query,
|
42
58
|
result: result,
|
43
59
|
logs: logs,
|
44
|
-
error: error.inspect,
|
60
|
+
error: error.present? ? error.inspect : nil,
|
45
61
|
query_mode: force_execution? ? 'force' : 'default',
|
46
62
|
project: ::RailsSpotlight::Support::Project.instance.name
|
47
63
|
}
|
@@ -61,6 +77,25 @@ module RailsSpotlight
|
|
61
77
|
@query ||= json_request_body.fetch('query')
|
62
78
|
end
|
63
79
|
|
80
|
+
def raw_options
|
81
|
+
@raw_options ||= json_request_body.fetch('options', {}) || {}
|
82
|
+
end
|
83
|
+
|
84
|
+
def required_projects
|
85
|
+
@required_projects ||= raw_options.fetch('projects', [])
|
86
|
+
end
|
87
|
+
|
88
|
+
def use
|
89
|
+
@use ||= { 'shard' => 'default', 'role' => 'reading' }.merge(raw_options.fetch('use', {}))
|
90
|
+
end
|
91
|
+
|
92
|
+
def connection_options
|
93
|
+
@connection_options ||= raw_options
|
94
|
+
.symbolize_keys
|
95
|
+
.slice(:database, :shards)
|
96
|
+
.reject { |_, v| v.nil? || (!v.is_a?(TrueClass) && !v.is_a?(FalseClass) && v.empty?) } # TODO: Check for each rails version
|
97
|
+
end
|
98
|
+
|
64
99
|
def force_execution?
|
65
100
|
@force_execution ||= json_request_body['mode'] == 'force'
|
66
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_spotlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pawel Niemczyk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack-contrib
|
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
213
|
- !ruby/object:Gem::Version
|
214
214
|
version: '0'
|
215
215
|
requirements: []
|
216
|
-
rubygems_version: 3.
|
216
|
+
rubygems_version: 3.3.3
|
217
217
|
signing_key:
|
218
218
|
specification_version: 4
|
219
219
|
summary: Lets have a look at your rails application in details
|