dbviewer 0.5.1 → 0.5.2

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: d16f8924e91f06f61088b4948397aa23530cd6e4a89e00ab483cc047ea5fc492
4
- data.tar.gz: 98091d292dfe7c42f0644dc1734fb298f532cfc6f99e0176ff1ae517c8db1cc8
3
+ metadata.gz: fff65e39ec4f823de37b99cf4b60c49d998e56bf2ff10cde22e9d664ea193fdc
4
+ data.tar.gz: 3ad5a045ab31b37c8f8d7ae410499f9f16a9a10fe8a52a8b3161e331cb3f0f6a
5
5
  SHA512:
6
- metadata.gz: a423fec219eaf8f40adde10a316cd4e45f33eb27d514ead5a0da735db3a475ac1ac430851cc347095106ca011dda72eae4ab68a01cba8ea8782ab132c99de8b6
7
- data.tar.gz: 57594e053bf4bd1389da099fa91236af80e579bfc6f0ebd72da5081187c16a2343717c803632781bf39eb8d5281151cc8614def62c035b1b35dfd2f8946da631
6
+ metadata.gz: 72f824b283bd82504319fe5002d48d1f8a7cd29f4038773d4e75ff7c8e9ba250e27de2239eee36adac6ff10740e5779a5272f0c202f2bb1ccb32c586f94ea093
7
+ data.tar.gz: 655d0bd7d9ea5fc5c70e338b8bdea8dd000b8fd25984c267243598a02afcaff50ba185d80d123b9e2203148b82945f13ebc47d470ef900252887cdfe4134d3c6
data/README.md CHANGED
@@ -7,7 +7,6 @@ It's designed for development, debugging, and database analysis, offering a clea
7
7
 
8
8
  <img width="1470" alt="image" src="https://github.com/user-attachments/assets/0d2719ad-f5b4-4818-891d-5bff7be6c5c3" />
9
9
 
10
-
11
10
  ## ✨ Features
12
11
 
13
12
  - **Dashboard**: View a comprehensive dashboard with database analytics, largest tables, most complex tables, and recent SQL queries
@@ -270,6 +269,70 @@ The simplest way to update is using Bundler:
270
269
  rails server
271
270
  ```
272
271
 
272
+ ## 🛠️ Development Setup
273
+
274
+ To set up the development environment for contributing to DBViewer:
275
+
276
+ ### Quick Setup
277
+
278
+ Run the setup script to automatically configure your development environment:
279
+
280
+ ```bash
281
+ bin/setup
282
+ ```
283
+
284
+ This script will:
285
+
286
+ - Install bundler and gem dependencies
287
+ - Set up the test dummy Rails application
288
+ - Create and seed the development database
289
+ - Prepare the test environment
290
+ - Clean up old logs and temporary files
291
+
292
+ ### Manual Setup
293
+
294
+ If you prefer to set up manually:
295
+
296
+ ```bash
297
+ # Install dependencies
298
+ bundle install
299
+
300
+ # Set up the dummy app database
301
+ cd test/dummy
302
+ bin/rails db:prepare
303
+ bin/rails db:migrate
304
+ bin/rails db:seed
305
+ cd ../..
306
+
307
+ # Prepare test environment
308
+ cd test/dummy && bin/rails db:test:prepare && cd ../..
309
+ ```
310
+
311
+ ### Development Commands
312
+
313
+ ```bash
314
+ # Start the development server
315
+ cd test/dummy && bin/rails server
316
+
317
+ # Run tests
318
+ bundle exec rspec
319
+
320
+ # Run code quality checks
321
+ bin/rubocop
322
+
323
+ # Open an interactive console
324
+ bin/console
325
+
326
+ # Build the gem
327
+ gem build dbviewer.gemspec
328
+ ```
329
+
330
+ ### Testing Your Changes
331
+
332
+ 1. Start the dummy Rails application: `cd test/dummy && bin/rails server`
333
+ 2. Visit `http://localhost:3000/dbviewer` to test your changes
334
+ 3. The dummy app includes sample data across multiple tables to test various DBViewer features
335
+
273
336
  ## 🤌🏻 Contributing
274
337
 
275
338
  Bug reports and pull requests are welcome.
@@ -2,9 +2,10 @@ module Dbviewer
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Dbviewer
4
4
 
5
- # Ensure lib directory is in the autoload path
6
- config.autoload_paths << File.expand_path("../../", __FILE__)
7
- config.eager_load_paths << File.expand_path("../../", __FILE__)
5
+ # Autoload lib directory
6
+ lib_path = File.expand_path("..", __dir__)
7
+ config.autoload_paths << lib_path
8
+ config.eager_load_paths << lib_path
8
9
 
9
10
  # Register generators
10
11
  config.app_generators do |g|
@@ -18,12 +19,14 @@ module Dbviewer
18
19
  end
19
20
 
20
21
  initializer "dbviewer.notifications" do
22
+ return unless Rails.env.development?
23
+
21
24
  ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
22
25
  event = ActiveSupport::Notifications::Event.new(*args)
23
26
 
24
27
  next if skip_internal_query?(event)
25
28
 
26
- Logger.instance.add(event)
29
+ Dbviewer::Logger.instance.add(event)
27
30
  end
28
31
  end
29
32
 
@@ -33,10 +36,10 @@ module Dbviewer
33
36
  caller_locations = caller_locations(1)
34
37
  return false unless caller_locations
35
38
 
36
- # Look for dbviewer in the call stack
37
- caller_locations.any? { |l| l.path.include?("dbviewer") }
38
- rescue
39
- false
39
+ excluded_caller_locations = caller_locations.filter do |caller_location|
40
+ !caller_location.path.include?("lib/dbviewer/engine.rb")
41
+ end
42
+ excluded_caller_locations.any? { |l| l.path.include?("dbviewer") }
40
43
  end
41
44
  end
42
45
  end
@@ -12,6 +12,7 @@ module Dbviewer
12
12
  def add(event)
13
13
  # Return early if query logging is disabled
14
14
  return unless Dbviewer.configuration.enable_query_logging
15
+ return if QueryParser.should_skip_query?(event)
15
16
 
16
17
  current_time = Time.now
17
18
  @storage.add({
@@ -20,7 +21,7 @@ module Dbviewer
20
21
  timestamp: current_time,
21
22
  duration_ms: event.duration.round(2),
22
23
  binds: QueryParser.format_binds(event.payload[:binds]),
23
- request_id: event.transaction_id || current_time.to_i,
24
+ request_id: ActiveSupport::Notifications.instrumenter.id,
24
25
  thread_id: Thread.current.object_id.to_s,
25
26
  caller: event.payload[:caller]
26
27
  })
@@ -22,36 +22,6 @@ module Dbviewer
22
22
  .gsub(/"[^"]*"/, '"X"')
23
23
  end
24
24
 
25
- # Check if the query is from the DBViewer library
26
- def self.from_dbviewer?(event)
27
- # Check if the SQL itself references DBViewer tables
28
- if event.payload[:sql].match(/\b(from|join|update|into)\s+["`']?dbviewer_/i)
29
- return true
30
- end
31
-
32
- # Check the caller information if available
33
- caller = event.payload[:caller]
34
- if caller.is_a?(String) && caller.include?("/dbviewer/")
35
- return true
36
- end
37
-
38
- # Check if query name indicates it's from DBViewer
39
- if event.payload[:name].is_a?(String) &&
40
- (event.payload[:name].include?("Dbviewer") || event.payload[:name].include?("DBViewer") || event.payload[:name] == "SQL")
41
- return true
42
- end
43
-
44
- # Check for common DBViewer operations
45
- sql = event.payload[:sql].downcase
46
- if sql.include?("table_structure") ||
47
- sql.include?("schema_migrations") ||
48
- sql.include?("database_analytics")
49
- return true
50
- end
51
-
52
- false
53
- end
54
-
55
25
  # Format bind parameters for storage
56
26
  def self.format_binds(binds)
57
27
  return [] unless binds.respond_to?(:map)
@@ -68,5 +38,16 @@ module Dbviewer
68
38
  rescue
69
39
  []
70
40
  end
41
+
42
+ # Determine if a query should be skipped based on content
43
+ # Rails and ActiveRecord often run internal queries that are not useful for logging
44
+ def self.should_skip_query?(event)
45
+ event.payload[:name] == "SCHEMA" ||
46
+ event.payload[:sql].include?("SHOW TABLES") ||
47
+ event.payload[:sql].include?("sqlite_master") ||
48
+ event.payload[:sql].include?("information_schema") ||
49
+ event.payload[:sql].include?("schema_migrations") ||
50
+ event.payload[:sql].include?("pg_catalog")
51
+ end
71
52
  end
72
53
  end
@@ -1,3 +1,3 @@
1
1
  module Dbviewer
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbviewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wailan Tirajoh