pg_insights 0.1.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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +183 -0
  4. data/Rakefile +8 -0
  5. data/app/assets/javascripts/pg_insights/application.js +436 -0
  6. data/app/assets/javascripts/pg_insights/health.js +104 -0
  7. data/app/assets/javascripts/pg_insights/results/chart_renderer.js +126 -0
  8. data/app/assets/javascripts/pg_insights/results/table_manager.js +378 -0
  9. data/app/assets/javascripts/pg_insights/results/view_toggles.js +25 -0
  10. data/app/assets/javascripts/pg_insights/results.js +13 -0
  11. data/app/assets/stylesheets/pg_insights/application.css +750 -0
  12. data/app/assets/stylesheets/pg_insights/health.css +501 -0
  13. data/app/assets/stylesheets/pg_insights/results.css +682 -0
  14. data/app/controllers/pg_insights/application_controller.rb +4 -0
  15. data/app/controllers/pg_insights/health_controller.rb +110 -0
  16. data/app/controllers/pg_insights/insights_controller.rb +77 -0
  17. data/app/controllers/pg_insights/queries_controller.rb +44 -0
  18. data/app/helpers/pg_insights/application_helper.rb +4 -0
  19. data/app/helpers/pg_insights/insights_helper.rb +190 -0
  20. data/app/jobs/pg_insights/application_job.rb +4 -0
  21. data/app/jobs/pg_insights/health_check_job.rb +45 -0
  22. data/app/jobs/pg_insights/health_check_scheduler_job.rb +52 -0
  23. data/app/jobs/pg_insights/recurring_health_checks_job.rb +49 -0
  24. data/app/models/pg_insights/application_record.rb +5 -0
  25. data/app/models/pg_insights/health_check_result.rb +46 -0
  26. data/app/models/pg_insights/query.rb +10 -0
  27. data/app/services/pg_insights/health_check_service.rb +298 -0
  28. data/app/services/pg_insights/insight_query_service.rb +21 -0
  29. data/app/views/layouts/pg_insights/application.html.erb +58 -0
  30. data/app/views/pg_insights/health/index.html.erb +324 -0
  31. data/app/views/pg_insights/insights/_chart_view.html.erb +25 -0
  32. data/app/views/pg_insights/insights/_column_panel.html.erb +18 -0
  33. data/app/views/pg_insights/insights/_query_examples.html.erb +32 -0
  34. data/app/views/pg_insights/insights/_query_panel.html.erb +36 -0
  35. data/app/views/pg_insights/insights/_result.html.erb +15 -0
  36. data/app/views/pg_insights/insights/_results_info.html.erb +19 -0
  37. data/app/views/pg_insights/insights/_results_panel.html.erb +13 -0
  38. data/app/views/pg_insights/insights/_results_table.html.erb +45 -0
  39. data/app/views/pg_insights/insights/_stats_view.html.erb +3 -0
  40. data/app/views/pg_insights/insights/_table_controls.html.erb +21 -0
  41. data/app/views/pg_insights/insights/_table_view.html.erb +5 -0
  42. data/app/views/pg_insights/insights/index.html.erb +5 -0
  43. data/config/default_queries.yml +85 -0
  44. data/config/routes.rb +22 -0
  45. data/lib/generators/pg_insights/clean_generator.rb +74 -0
  46. data/lib/generators/pg_insights/install_generator.rb +176 -0
  47. data/lib/pg_insights/engine.rb +40 -0
  48. data/lib/pg_insights/version.rb +3 -0
  49. data/lib/pg_insights.rb +83 -0
  50. data/lib/tasks/pg_insights.rake +172 -0
  51. metadata +124 -0
@@ -0,0 +1,682 @@
1
+ /* PG Insights Results Styles */
2
+
3
+ /* Results Info Bar */
4
+ .results-info {
5
+ display: flex;
6
+ justify-content: space-between;
7
+ align-items: center;
8
+ flex-wrap: wrap;
9
+ gap: 12px;
10
+ padding: 12px 16px;
11
+ background: #f8fafc;
12
+ border-bottom: 1px solid #e2e8f0;
13
+ font-size: 13px;
14
+ color: #6b7280;
15
+ font-weight: 500;
16
+ flex-shrink: 0;
17
+ }
18
+
19
+ .results-meta {
20
+ font-weight: 500;
21
+ }
22
+
23
+ /* View Toggle */
24
+ .view-toggle {
25
+ display: flex;
26
+ gap: 4px;
27
+ background: #f1f5f9;
28
+ padding: 4px;
29
+ border-radius: 8px;
30
+ }
31
+
32
+ .toggle-btn {
33
+ padding: 6px 12px;
34
+ border: none;
35
+ background: transparent;
36
+ color: #64748b;
37
+ font-size: 12px;
38
+ font-weight: 500;
39
+ border-radius: 6px;
40
+ cursor: pointer;
41
+ transition: all 0.2s ease;
42
+ display: flex;
43
+ align-items: center;
44
+ gap: 4px;
45
+ }
46
+
47
+ .toggle-btn.active {
48
+ background: white;
49
+ color: #00979D;
50
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
51
+ }
52
+
53
+ .toggle-btn:hover:not(.active) {
54
+ background: rgba(255,255,255,0.5);
55
+ color: #475569;
56
+ }
57
+
58
+ .toggle-icon {
59
+ font-size: 14px;
60
+ }
61
+
62
+ /* Chart Container */
63
+ .chart-container {
64
+ padding: 20px;
65
+ background: white;
66
+ flex: 1;
67
+ display: flex;
68
+ flex-direction: column;
69
+ overflow: hidden;
70
+ min-height: 0;
71
+ }
72
+
73
+ .chart-controls {
74
+ display: flex;
75
+ align-items: center;
76
+ gap: 12px;
77
+ margin-bottom: 16px;
78
+ flex-shrink: 0;
79
+ }
80
+
81
+ .chart-label {
82
+ font-size: 12px;
83
+ font-weight: 600;
84
+ color: #374151;
85
+ }
86
+
87
+ .chart-select {
88
+ padding: 6px 10px;
89
+ border: 1px solid #d1d5db;
90
+ border-radius: 6px;
91
+ font-size: 12px;
92
+ background: white;
93
+ color: #374151;
94
+ cursor: pointer;
95
+ transition: border-color 0.2s ease;
96
+ }
97
+
98
+ .chart-select:focus {
99
+ outline: none;
100
+ border-color: #00979D;
101
+ box-shadow: 0 0 0 3px rgba(0, 151, 157, 0.1);
102
+ }
103
+
104
+ .chart-display {
105
+ flex: 1;
106
+ min-height: 0;
107
+ display: flex;
108
+ flex-direction: column;
109
+ position: relative;
110
+ }
111
+
112
+ /* Chart wrapper with proper constraints */
113
+ #dynamicChart {
114
+ flex: 1;
115
+ min-height: 250px;
116
+ max-height: 500px;
117
+ position: relative;
118
+ overflow: hidden;
119
+ }
120
+
121
+ /* Ensure ChartKick charts fit container */
122
+ #dynamicChart .chartkick {
123
+ height: 100% !important;
124
+ width: 100% !important;
125
+ }
126
+
127
+ #dynamicChart canvas {
128
+ max-width: 100% !important;
129
+ max-height: 100% !important;
130
+ }
131
+
132
+ /* Chart.js container fix */
133
+ #dynamicChart .chartjs-render-monitor {
134
+ height: 100% !important;
135
+ width: 100% !important;
136
+ }
137
+
138
+ .no-chart-message {
139
+ display: flex;
140
+ flex-direction: column;
141
+ align-items: center;
142
+ justify-content: center;
143
+ height: 300px;
144
+ color: #6b7280;
145
+ text-align: center;
146
+ }
147
+
148
+ .no-chart-message .chart-icon {
149
+ font-size: 48px;
150
+ margin-bottom: 16px;
151
+ opacity: 0.5;
152
+ }
153
+
154
+ .no-chart-message h3 {
155
+ font-size: 18px;
156
+ font-weight: 600;
157
+ color: #374151;
158
+ margin: 0 0 8px 0;
159
+ }
160
+
161
+ .no-chart-message p {
162
+ font-size: 14px;
163
+ margin: 0;
164
+ max-width: 300px;
165
+ }
166
+
167
+ /* Responsive chart sizing */
168
+ @media (max-width: 768px) {
169
+ #dynamicChart {
170
+ min-height: 200px;
171
+ max-height: 300px;
172
+ }
173
+ }
174
+
175
+ @media (max-width: 480px) {
176
+ .chart-container {
177
+ padding: 12px;
178
+ }
179
+
180
+ #dynamicChart {
181
+ min-height: 180px;
182
+ max-height: 250px;
183
+ }
184
+ }
185
+
186
+ /* Stats Container */
187
+ .stats-container {
188
+ padding: 20px;
189
+ background: white;
190
+ flex: 1;
191
+ overflow-y: auto;
192
+ }
193
+
194
+ .stats-grid {
195
+ display: grid;
196
+ grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
197
+ gap: 16px;
198
+ margin-top: 16px;
199
+ }
200
+
201
+ .stat-card {
202
+ background: #f8fafc;
203
+ border: 1px solid #e2e8f0;
204
+ border-radius: 8px;
205
+ padding: 16px;
206
+ text-align: center;
207
+ transition: transform 0.2s ease, box-shadow 0.2s ease;
208
+ }
209
+
210
+ .stat-card:hover {
211
+ transform: translateY(-2px);
212
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
213
+ }
214
+
215
+ .stat-value {
216
+ font-size: 24px;
217
+ font-weight: 700;
218
+ color: #00979D;
219
+ margin-bottom: 4px;
220
+ }
221
+
222
+ .stat-label {
223
+ font-size: 12px;
224
+ color: #6b7280;
225
+ font-weight: 500;
226
+ text-transform: uppercase;
227
+ letter-spacing: 0.5px;
228
+ }
229
+
230
+ .stats-section h4 {
231
+ color: #374151;
232
+ font-size: 16px;
233
+ font-weight: 600;
234
+ margin: 0 0 8px 0;
235
+ }
236
+
237
+ /* Table Container */
238
+ .table-container {
239
+ background: white;
240
+ flex: 1;
241
+ display: flex;
242
+ flex-direction: column;
243
+ overflow: hidden;
244
+ min-height: 0;
245
+ }
246
+
247
+ /* Table Controls */
248
+ .table-controls {
249
+ display: flex;
250
+ justify-content: space-between;
251
+ align-items: center;
252
+ padding: 12px 16px;
253
+ background: #f8fafc;
254
+ border-bottom: 1px solid #e2e8f0;
255
+ flex-wrap: wrap;
256
+ gap: 12px;
257
+ }
258
+
259
+ .table-info {
260
+ font-size: 13px;
261
+ color: #6b7280;
262
+ font-weight: 500;
263
+ }
264
+
265
+ .table-actions {
266
+ display: flex;
267
+ gap: 8px;
268
+ align-items: center;
269
+ }
270
+
271
+ .table-btn {
272
+ padding: 6px 12px;
273
+ border: 1px solid #d1d5db;
274
+ background: white;
275
+ color: #374151;
276
+ font-size: 12px;
277
+ font-weight: 500;
278
+ border-radius: 6px;
279
+ cursor: pointer;
280
+ transition: all 0.2s ease;
281
+ display: flex;
282
+ align-items: center;
283
+ gap: 4px;
284
+ }
285
+
286
+ .table-btn:hover {
287
+ border-color: #00979D;
288
+ color: #00979D;
289
+ background: #f0f9ff;
290
+ }
291
+
292
+ .btn-icon {
293
+ font-size: 14px;
294
+ }
295
+
296
+ /* Column Panel */
297
+ .column-panel {
298
+ position: absolute;
299
+ top: 60px;
300
+ right: 16px;
301
+ background: white;
302
+ border: 1px solid #e2e8f0;
303
+ border-radius: 8px;
304
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
305
+ z-index: 10;
306
+ min-width: 250px;
307
+ max-height: 400px;
308
+ display: none;
309
+ }
310
+
311
+ .column-panel-header {
312
+ padding: 12px 16px;
313
+ border-bottom: 1px solid #e2e8f0;
314
+ background: #f8fafc;
315
+ border-radius: 8px 8px 0 0;
316
+ }
317
+
318
+ .column-panel-header h4 {
319
+ margin: 0 0 8px 0;
320
+ font-size: 14px;
321
+ font-weight: 600;
322
+ color: #374151;
323
+ }
324
+
325
+ .column-panel-actions {
326
+ display: flex;
327
+ gap: 8px;
328
+ }
329
+
330
+ .panel-btn {
331
+ padding: 4px 8px;
332
+ border: 1px solid #d1d5db;
333
+ background: white;
334
+ color: #374151;
335
+ font-size: 11px;
336
+ font-weight: 500;
337
+ border-radius: 4px;
338
+ cursor: pointer;
339
+ transition: all 0.2s ease;
340
+ }
341
+
342
+ .panel-btn:hover {
343
+ border-color: #00979D;
344
+ color: #00979D;
345
+ }
346
+
347
+ .column-checkboxes {
348
+ max-height: 300px;
349
+ overflow-y: auto;
350
+ padding: 8px;
351
+ }
352
+
353
+ .column-checkbox {
354
+ display: flex;
355
+ align-items: center;
356
+ padding: 6px 8px;
357
+ border-radius: 4px;
358
+ cursor: pointer;
359
+ transition: background-color 0.2s ease;
360
+ }
361
+
362
+ .column-checkbox:hover {
363
+ background: #f1f5f9;
364
+ }
365
+
366
+ .column-toggle {
367
+ margin-right: 8px;
368
+ }
369
+
370
+ .checkbox-label {
371
+ font-size: 12px;
372
+ color: #374151;
373
+ cursor: pointer;
374
+ user-select: none;
375
+ }
376
+
377
+ /* Enhanced Table Wrapper */
378
+ .table-wrapper {
379
+ flex: 1;
380
+ position: relative;
381
+ overflow: hidden;
382
+ min-height: 0;
383
+ }
384
+
385
+ .table-scroll {
386
+ height: 100%;
387
+ overflow: auto;
388
+ position: relative;
389
+ }
390
+
391
+ /* Enhanced Results Table */
392
+ .results-table {
393
+ width: 100%;
394
+ border-collapse: separate;
395
+ border-spacing: 0;
396
+ font-size: 12px;
397
+ font-family: 'Monaco', 'Menlo', 'Consolas', 'SF Mono', monospace;
398
+ background: white;
399
+ }
400
+
401
+ /* Sticky Header */
402
+ .sticky-header {
403
+ position: sticky;
404
+ top: 0;
405
+ z-index: 5;
406
+ }
407
+
408
+ .results-table th {
409
+ background: #f8fafc;
410
+ border-bottom: 2px solid #e2e8f0;
411
+ border-right: 1px solid #e2e8f0;
412
+ padding: 8px 12px;
413
+ text-align: left;
414
+ font-weight: 600;
415
+ color: #374151;
416
+ white-space: nowrap;
417
+ position: relative;
418
+ user-select: none;
419
+ min-width: 100px;
420
+ max-width: 300px;
421
+ overflow: hidden;
422
+ }
423
+
424
+ .table-header-content {
425
+ display: flex;
426
+ flex-direction: column;
427
+ gap: 4px;
428
+ }
429
+
430
+ .header-text {
431
+ font-size: 12px;
432
+ font-weight: 600;
433
+ color: #374151;
434
+ }
435
+
436
+ .header-type {
437
+ font-size: 9px;
438
+ font-weight: 500;
439
+ text-transform: uppercase;
440
+ letter-spacing: 0.3px;
441
+ padding: 1px 4px;
442
+ border-radius: 8px;
443
+ background: #f1f5f9;
444
+ color: #64748b;
445
+ align-self: flex-start;
446
+ }
447
+
448
+ /* Sticky Row Numbers */
449
+ .row-num {
450
+ background: #f8fafc;
451
+ border-right: 2px solid #e2e8f0;
452
+ border-bottom: 1px solid #e2e8f0;
453
+ padding: 6px 8px;
454
+ text-align: center;
455
+ font-weight: 600;
456
+ color: #6b7280;
457
+ font-size: 11px;
458
+ position: sticky;
459
+ left: 0;
460
+ z-index: 3;
461
+ min-width: 50px;
462
+ max-width: 50px;
463
+ width: 50px;
464
+ }
465
+
466
+ .sticky-header .row-num {
467
+ z-index: 6;
468
+ }
469
+
470
+ /* Table Cells */
471
+ .results-table td {
472
+ border-bottom: 1px solid #f1f5f9;
473
+ border-right: 1px solid #f1f5f9;
474
+ padding: 6px 12px;
475
+ vertical-align: top;
476
+ white-space: nowrap;
477
+ overflow: hidden;
478
+ text-overflow: ellipsis;
479
+ min-width: 100px;
480
+ max-width: 300px;
481
+ position: relative;
482
+ }
483
+
484
+ .cell-content {
485
+ display: block;
486
+ max-width: 100%;
487
+ overflow: hidden;
488
+ text-overflow: ellipsis;
489
+ line-height: 1.4;
490
+ }
491
+
492
+ /* Row Styling */
493
+ .even-row td {
494
+ background: #fafbfc;
495
+ }
496
+
497
+ .results-table tr:hover td {
498
+ background: #f0f9ff !important;
499
+ }
500
+
501
+ .results-table tr:hover .row-num {
502
+ background: #e0f2fe !important;
503
+ color: #00979D;
504
+ }
505
+
506
+ /* Cell Value Types */
507
+ .null-value {
508
+ color: #9ca3af;
509
+ font-style: italic;
510
+ opacity: 0.7;
511
+ }
512
+
513
+ .empty-value {
514
+ color: #d1d5db;
515
+ font-style: italic;
516
+ opacity: 0.5;
517
+ }
518
+
519
+ .numeric-value {
520
+ color: #059669;
521
+ font-weight: 500;
522
+ text-align: right;
523
+ }
524
+
525
+ .long-text {
526
+ max-width: 200px;
527
+ white-space: normal;
528
+ word-wrap: break-word;
529
+ line-height: 1.3;
530
+ }
531
+
532
+ .text-value {
533
+ color: #374151;
534
+ }
535
+
536
+ /* Hidden Columns */
537
+ .column-hidden {
538
+ display: none !important;
539
+ }
540
+
541
+ /* Scroll Indicators */
542
+ .scroll-indicator {
543
+ position: absolute;
544
+ background: rgba(0,0,0,0.1);
545
+ border-radius: 4px;
546
+ opacity: 0;
547
+ transition: opacity 0.3s ease;
548
+ pointer-events: none;
549
+ }
550
+
551
+ .scroll-indicator.visible {
552
+ opacity: 1;
553
+ }
554
+
555
+ .scroll-indicator-horizontal {
556
+ bottom: 4px;
557
+ left: 4px;
558
+ right: 4px;
559
+ height: 8px;
560
+ }
561
+
562
+ .scroll-indicator-vertical {
563
+ top: 4px;
564
+ right: 4px;
565
+ bottom: 4px;
566
+ width: 8px;
567
+ }
568
+
569
+ .scroll-thumb {
570
+ background: rgba(0,0,0,0.4);
571
+ border-radius: 4px;
572
+ position: absolute;
573
+ transition: background-color 0.2s ease;
574
+ }
575
+
576
+ .scroll-thumb:hover {
577
+ background: rgba(0,0,0,0.6);
578
+ }
579
+
580
+ /* Column Resize Handle */
581
+ .resize-handle {
582
+ position: absolute;
583
+ top: 0;
584
+ right: 0;
585
+ width: 4px;
586
+ height: 100%;
587
+ cursor: col-resize;
588
+ background: transparent;
589
+ z-index: 1;
590
+ }
591
+
592
+ .resize-handle:hover {
593
+ background: #00979D;
594
+ }
595
+
596
+ /* Table Loading State */
597
+ .table-loading {
598
+ text-align: center;
599
+ padding: 40px;
600
+ color: #6b7280;
601
+ font-style: italic;
602
+ }
603
+
604
+ /* Responsive Table */
605
+ @media (max-width: 768px) {
606
+ .results-table {
607
+ font-size: 11px;
608
+ }
609
+
610
+ .results-table th,
611
+ .results-table td {
612
+ padding: 4px 8px;
613
+ min-width: 80px;
614
+ }
615
+
616
+ .table-controls {
617
+ flex-direction: column;
618
+ align-items: stretch;
619
+ }
620
+
621
+ .table-actions {
622
+ justify-content: center;
623
+ }
624
+
625
+ .column-panel {
626
+ position: fixed;
627
+ top: 50%;
628
+ left: 50%;
629
+ transform: translate(-50%, -50%);
630
+ max-height: 60vh;
631
+ width: 90vw;
632
+ max-width: 400px;
633
+ }
634
+ }
635
+
636
+ /* Error message styling */
637
+ .error-message {
638
+ padding: 16px;
639
+ background: #fef2f2;
640
+ color: #dc2626;
641
+ border-radius: 6px;
642
+ border: 1px solid #fecaca;
643
+ display: flex;
644
+ align-items: center;
645
+ gap: 8px;
646
+ font-size: 14px;
647
+ }
648
+
649
+ .error-icon {
650
+ font-size: 16px;
651
+ flex-shrink: 0;
652
+ }
653
+
654
+ /* ChartKick overrides */
655
+ .chartkick {
656
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
657
+ }
658
+
659
+ /* Responsive */
660
+ @media (max-width: 768px) {
661
+ .results-info {
662
+ flex-direction: column;
663
+ align-items: stretch;
664
+ }
665
+
666
+ .view-toggle {
667
+ justify-content: center;
668
+ }
669
+
670
+ .stats-grid {
671
+ grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
672
+ gap: 12px;
673
+ }
674
+
675
+ .stat-card {
676
+ padding: 12px;
677
+ }
678
+
679
+ .stat-value {
680
+ font-size: 20px;
681
+ }
682
+ }
@@ -0,0 +1,4 @@
1
+ module PgInsights
2
+ class ApplicationController < ::ApplicationController
3
+ end
4
+ end