findbug 0.4.0 → 0.5.0

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.
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Findbug
4
+ module AdapterHelper
5
+ def self.adapter_name
6
+ ActiveRecord::Base.connection.adapter_name.downcase
7
+ rescue StandardError
8
+ "postgresql"
9
+ end
10
+
11
+ def self.postgresql?
12
+ name = adapter_name
13
+ name.include?("postgresql") || name.include?("postgis")
14
+ end
15
+
16
+ def self.mysql?
17
+ adapter_name.include?("mysql")
18
+ end
19
+
20
+ def self.sqlite?
21
+ adapter_name.include?("sqlite")
22
+ end
23
+
24
+ # Returns the appropriate column type symbol for JSON storage.
25
+ # :jsonb on PostgreSQL, :json on MySQL, :text on SQLite.
26
+ def self.json_column_type
27
+ if postgresql?
28
+ :jsonb
29
+ elsif mysql?
30
+ :json
31
+ else
32
+ :text
33
+ end
34
+ end
35
+
36
+ # Returns an adapter-appropriate column default for a JSON field.
37
+ #
38
+ # PostgreSQL jsonb accepts a Hash/Array directly.
39
+ # MySQL JSON columns don't support DEFAULT values (pre-8.0.13), so we return nil.
40
+ # SQLite text columns need a JSON-encoded String.
41
+ def self.json_default(value)
42
+ if postgresql?
43
+ value
44
+ elsif mysql?
45
+ nil
46
+ else
47
+ value.to_json
48
+ end
49
+ end
50
+
51
+ # Returns adapter-specific SQL to truncate a timestamp column to an interval.
52
+ # interval: 'minute', 'hour', or 'day' (anything else falls back to 'hour')
53
+ # column: SQL column name, e.g. 'captured_at'
54
+ def self.date_trunc_sql(interval, column)
55
+ bucket = %w[minute hour day].include?(interval) ? interval : "hour"
56
+
57
+ if postgresql?
58
+ "date_trunc('#{bucket}', #{column})"
59
+ elsif mysql?
60
+ case bucket
61
+ when "minute" then "DATE_FORMAT(#{column}, '%Y-%m-%d %H:%i:00')"
62
+ when "day" then "DATE(#{column})"
63
+ else "DATE_FORMAT(#{column}, '%Y-%m-%d %H:00:00')"
64
+ end
65
+ else # SQLite and unknown adapters
66
+ case bucket
67
+ when "minute" then "strftime('%Y-%m-%d %H:%M:00', #{column})"
68
+ when "day" then "DATE(#{column})"
69
+ else "strftime('%Y-%m-%d %H:00:00', #{column})"
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Findbug
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/findbug.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "findbug/version"
4
4
  require_relative "findbug/configuration"
5
+ require_relative "findbug/adapter_helper"
5
6
 
6
7
  # Findbug - Self-hosted error tracking and performance monitoring for Rails
7
8
  #
@@ -9,9 +9,9 @@ class CreateFindbugErrorEvents < ActiveRecord::Migration<%= migration_version %>
9
9
  t.text :message
10
10
  t.text :backtrace
11
11
 
12
- # Context (stored as JSON for flexibility)
13
- t.jsonb :context, default: {}
14
- t.jsonb :request_data, default: {}
12
+ # Context (stored as JSON for flexibility; type chosen based on adapter)
13
+ t.column :context, Findbug::AdapterHelper.json_column_type, default: Findbug::AdapterHelper.json_default({})
14
+ t.column :request_data, Findbug::AdapterHelper.json_column_type, default: Findbug::AdapterHelper.json_default({})
15
15
 
16
16
  # Metadata
17
17
  t.string :environment
@@ -20,13 +20,13 @@ class CreateFindbugPerformanceEvents < ActiveRecord::Migration<%= migration_vers
20
20
 
21
21
  # Query tracking
22
22
  t.integer :query_count, default: 0
23
- t.jsonb :slow_queries, default: []
24
- t.jsonb :n_plus_one_queries, default: []
23
+ t.column :slow_queries, Findbug::AdapterHelper.json_column_type, default: Findbug::AdapterHelper.json_default([])
24
+ t.column :n_plus_one_queries, Findbug::AdapterHelper.json_column_type, default: Findbug::AdapterHelper.json_default([])
25
25
  t.boolean :has_n_plus_one, default: false
26
26
  t.integer :view_count, default: 0
27
27
 
28
28
  # Context
29
- t.jsonb :context, default: {}
29
+ t.column :context, Findbug::AdapterHelper.json_column_type, default: Findbug::AdapterHelper.json_default({})
30
30
 
31
31
  # Metadata
32
32
  t.string :environment
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: findbug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soumit Das
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 2026-02-25 00:00:00.000000000 Z
11
+ date: 2026-05-16 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: railties
@@ -197,8 +198,10 @@ files:
197
198
  - app/views/findbug/performance/index.html.erb
198
199
  - app/views/findbug/performance/show.html.erb
199
200
  - app/views/layouts/findbug/application.html.erb
201
+ - docs/docs.html
200
202
  - docs/index.html
201
203
  - lib/findbug.rb
204
+ - lib/findbug/adapter_helper.rb
202
205
  - lib/findbug/alerts/channels/base.rb
203
206
  - lib/findbug/alerts/channels/discord.rb
204
207
  - lib/findbug/alerts/channels/email.rb
@@ -239,6 +242,7 @@ metadata:
239
242
  homepage_uri: https://findbug.dev
240
243
  source_code_uri: https://github.com/ITSSOUMIT/findbug
241
244
  changelog_uri: https://github.com/ITSSOUMIT/findbug/blob/main/CHANGELOG.md
245
+ post_install_message:
242
246
  rdoc_options: []
243
247
  require_paths:
244
248
  - lib
@@ -253,7 +257,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
257
  - !ruby/object:Gem::Version
254
258
  version: '0'
255
259
  requirements: []
256
- rubygems_version: 3.6.3
260
+ rubygems_version: 3.5.3
261
+ signing_key:
257
262
  specification_version: 4
258
263
  summary: Self-hosted error tracking and performance monitoring for Rails
259
264
  test_files: []