pg_insights 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5345562a5a6b419e8008d02a94cd9136252249ed4d1931f06583233f13ab2e7
4
- data.tar.gz: 3381256f037dbbc770164de14552b792e9bfe2437e273f4768bd5de40aac6560
3
+ metadata.gz: 8acfcade3c12305c32746590f4a929658316db90b6a447eafed0571acd3376a4
4
+ data.tar.gz: 718ebc8fc2c8488d7fc17658e204c7c4f2b1b26742013f804649b2ff6ca47136
5
5
  SHA512:
6
- metadata.gz: bd20373bfafbdc70ce5660013389b4030a419135292f7f3347b57d22105962e012e032499d732b31f1eed319f138832347ca999572c14041a99eec1fda8b90c4
7
- data.tar.gz: 8121527a9f0de02562c7f22fd6fd0ce935da86eca38c618493bddc23e9e0ded74c3d400ab3f85cba883febe3dcd563b1ef3c8b624c8924b818454201be8fde51
6
+ metadata.gz: 8f88375655df7257c743c72ebb210d7e17a446d8b12c8b29e36eed0cae4c6b8f4a036e0010207db67950a108df2752f69dee5f6f9afc099563c1ddf33c477691
7
+ data.tar.gz: f97b5851eea169936254692c0ab5b8cd7104e367294b77179c697552ef1c5b6815a0ac5e5cc2a3f919faf0c3f4fed540f94e6bcaa39aef8b39a9c09a55a6c421
@@ -13,7 +13,7 @@ module PgInsights
13
13
 
14
14
  @snapshots = HealthCheckResult.snapshots(90)
15
15
  @parameter_changes = HealthCheckResult.detect_parameter_changes_since(30)
16
- @timeline_data = HealthCheckResult.timeline_data(30)
16
+ @timeline_data = HealthCheckResult.timeline_data(30, @parameter_changes)
17
17
  @stats = calculate_timeline_stats(@snapshots)
18
18
  end
19
19
 
@@ -1,4 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PgInsights
2
4
  class ApplicationJob < ActiveJob::Base
5
+ queue_as do
6
+ PgInsights.background_job_queue
7
+ end
3
8
  end
4
9
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module PgInsights
4
4
  class DatabaseSnapshotJob < ApplicationJob
5
- queue_as -> { PgInsights.background_job_queue }
6
-
7
5
  rescue_from(StandardError) do |exception|
8
6
  Rails.logger.error "PgInsights::DatabaseSnapshotJob failed: #{exception.message}"
9
7
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module PgInsights
4
4
  class HealthCheckJob < ApplicationJob
5
- queue_as -> { PgInsights.background_job_queue }
6
-
7
5
  rescue_from(StandardError) do |exception|
8
6
  Rails.logger.error "PgInsights::HealthCheckJob failed: #{exception.message}"
9
7
  end
@@ -26,10 +24,6 @@ module PgInsights
26
24
  end
27
25
  end
28
26
 
29
- def self.queue_name
30
- PgInsights.background_job_queue
31
- end
32
-
33
27
  def self.perform_check(check_type, options = {})
34
28
  return false unless PgInsights.background_jobs_available?
35
29
 
@@ -2,8 +2,6 @@
2
2
 
3
3
  module PgInsights
4
4
  class HealthCheckSchedulerJob < ApplicationJob
5
- queue_as -> { PgInsights.background_job_queue }
6
-
7
5
  rescue_from(StandardError) do |exception|
8
6
  Rails.logger.error "PgInsights::HealthCheckSchedulerJob failed: #{exception.message}"
9
7
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module PgInsights
4
4
  class RecurringHealthChecksJob < ApplicationJob
5
- queue_as -> { PgInsights.background_job_queue }
6
-
7
5
  rescue_from(StandardError) do |exception|
8
6
  Rails.logger.error "PgInsights::RecurringHealthChecksJob failed: #{exception.message}"
9
7
  end
@@ -121,19 +121,23 @@ module PgInsights
121
121
  deleted_count
122
122
  end
123
123
 
124
- def self.timeline_data(days = 30)
124
+ def self.timeline_data(days = 30, parameter_changes = nil)
125
125
  snapshots = by_type("database_snapshot")
126
126
  .successful
127
127
  .where("executed_at >= ?", days.days.ago)
128
128
  .order(:executed_at)
129
129
 
130
+ build_timeline_data(snapshots, parameter_changes || detect_parameter_changes_since(days))
131
+ end
132
+
133
+ def self.build_timeline_data(snapshots, parameter_changes)
130
134
  {
131
135
  dates: snapshots.map { |s| s.executed_at.strftime("%Y-%m-%d %H:%M") },
132
136
  cache_hit_rates: snapshots.map { |s| (s.result_data.dig("metrics", "cache_hit_rate") || 0).to_f },
133
137
  avg_query_times: snapshots.map { |s| (s.result_data.dig("metrics", "avg_query_time") || 0).to_f },
134
138
  bloated_tables: snapshots.map { |s| (s.result_data.dig("metrics", "bloated_tables") || 0).to_i },
135
139
  total_connections: snapshots.map { |s| (s.result_data.dig("metrics", "total_connections") || 0).to_i },
136
- parameter_changes: detect_parameter_changes_since(days)
140
+ parameter_changes: parameter_changes
137
141
  }
138
142
  end
139
143
 
@@ -7,7 +7,7 @@ module PgInsights
7
7
  class InstallGenerator < Rails::Generators::Base
8
8
  include Rails::Generators::Migration
9
9
 
10
- source_root File.expand_path("../../../..", __FILE__)
10
+ source_root File.expand_path("templates", __dir__)
11
11
 
12
12
  def self.next_migration_number(dirname)
13
13
  ActiveRecord::Generators::Base.next_migration_number(dirname)
@@ -0,0 +1,16 @@
1
+ class CreatePgInsightsHealthCheckResults < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :pg_insights_health_check_results do |t|
4
+ t.string :check_type, null: false, limit: 50
5
+ t.json :result_data
6
+ t.string :status, null: false, default: "pending", limit: 20
7
+ t.text :error_message
8
+ t.datetime :executed_at
9
+ t.integer :execution_time_ms
10
+ t.timestamps
11
+
12
+ t.index [ :check_type, :executed_at ], name: "idx_pg_insights_health_check_type_executed_at"
13
+ t.index [ :status, :executed_at ], name: "idx_pg_insights_health_status_executed_at"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ class CreatePgInsightsQueries < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :pg_insights_queries do |t|
4
+ t.string :name, null: false
5
+ t.text :sql, null: false
6
+ t.string :description
7
+ t.string :category, null: false, default: "saved"
8
+ t.timestamps
9
+ end
10
+ add_index :pg_insights_queries, :name, unique: true
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module PgInsights
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_insights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mezbah Alam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-03 00:00:00.000000000 Z
11
+ date: 2025-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -96,6 +96,8 @@ files:
96
96
  - config/routes.rb
97
97
  - lib/generators/pg_insights/clean_generator.rb
98
98
  - lib/generators/pg_insights/install_generator.rb
99
+ - lib/generators/pg_insights/templates/db/migrate/create_pg_insights_health_check_results.rb
100
+ - lib/generators/pg_insights/templates/db/migrate/create_pg_insights_queries.rb
99
101
  - lib/pg_insights.rb
100
102
  - lib/pg_insights/engine.rb
101
103
  - lib/pg_insights/version.rb