mysql_genius 0.1.1 → 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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +5 -0
  3. data/.github/workflows/ci.yml +30 -7
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +24 -0
  6. data/CHANGELOG.md +32 -0
  7. data/Gemfile +7 -2
  8. data/README.md +50 -38
  9. data/Rakefile +3 -1
  10. data/app/controllers/concerns/mysql_genius/ai_features.rb +90 -52
  11. data/app/controllers/concerns/mysql_genius/database_analysis.rb +73 -45
  12. data/app/controllers/concerns/mysql_genius/query_execution.rb +18 -16
  13. data/app/controllers/mysql_genius/base_controller.rb +3 -1
  14. data/app/controllers/mysql_genius/queries_controller.rb +19 -12
  15. data/app/services/mysql_genius/ai_client.rb +9 -2
  16. data/app/services/mysql_genius/ai_optimization_service.rb +8 -4
  17. data/app/services/mysql_genius/ai_suggestion_service.rb +5 -2
  18. data/app/views/layouts/mysql_genius/application.html.erb +141 -5
  19. data/app/views/mysql_genius/queries/_tab_dashboard.html.erb +95 -0
  20. data/app/views/mysql_genius/queries/_tab_duplicate_indexes.html.erb +11 -0
  21. data/app/views/mysql_genius/queries/_tab_query_explorer.html.erb +110 -0
  22. data/app/views/mysql_genius/queries/_tab_table_sizes.html.erb +6 -4
  23. data/app/views/mysql_genius/queries/_tab_unused_indexes.html.erb +11 -0
  24. data/app/views/mysql_genius/queries/index.html.erb +377 -52
  25. data/bin/console +1 -0
  26. data/config/routes.rb +2 -0
  27. data/docs/screenshots/dashboard.png +0 -0
  28. data/docs/screenshots/query_explore.png +0 -0
  29. data/docs/superpowers/plans/2026-04-08-dashboard-first-redesign.md +741 -0
  30. data/docs/superpowers/specs/2026-04-08-dashboard-first-redesign.md +87 -0
  31. data/lib/generators/mysql_genius/install/install_generator.rb +19 -0
  32. data/lib/generators/mysql_genius/install/templates/initializer.rb +56 -0
  33. data/lib/mysql_genius/configuration.rb +8 -6
  34. data/lib/mysql_genius/engine.rb +2 -0
  35. data/lib/mysql_genius/slow_query_monitor.rb +29 -25
  36. data/lib/mysql_genius/sql_validator.rb +6 -4
  37. data/lib/mysql_genius/version.rb +3 -1
  38. data/lib/mysql_genius.rb +2 -0
  39. data/mysql_genius.gemspec +9 -8
  40. metadata +19 -15
  41. data/app/views/mysql_genius/queries/_tab_sql_query.html.erb +0 -40
  42. data/app/views/mysql_genius/queries/_tab_visual_builder.html.erb +0 -61
  43. data/docs/screenshots/sql_query.png +0 -0
  44. data/docs/screenshots/visual_builder.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f530f740e6b3ee60b96d1d5c593e43bc84999b5c07c1916538dece3c4030841
4
- data.tar.gz: 1b9c5cae76c1375ae70d98772a45f3f443926401612b27587803d3aa245e6d55
3
+ metadata.gz: cac820a4fce8c58c24e922c9d1794b5e643c83c36c087dbf19ec5f34b41dd7ff
4
+ data.tar.gz: 382817839d37e85caa3265ef4bedff6073d1f417d5d33c3295881e1b8d745044
5
5
  SHA512:
6
- metadata.gz: 4f7888b035691889ca0c62b22d9a041f2b44979c25cb3d6ef743100e86a88bf0371c239ef72bbf4c48a0ea05086fb925117b8013b3b2b96129a73884f8f1ab11
7
- data.tar.gz: 8e2dad89645394daecd5ffe15fffdb05aca7ab0eca66512c5f06688af13e0c35206ae2e489f83782c2b9b7f63ceac5bacb085109e6d7e30788e4e90cbdbb6284
6
+ metadata.gz: 8676b5b731e2df5df4392a46533c395c72dde5b00323f965f23429f8598b68f64d40a974ee31dcfa52bc6ab5810ad6f2fc2f8ad7f07a69dea75df63d6b128564
7
+ data.tar.gz: fe0708d066c4aa9779fc8eaaf849c03ef0943031c4871201be840a3f34bebf481b3f89e02f477700e2c32c4611a0fead1b2cd8f462cd17a928a4f66a8c38435b
@@ -0,0 +1,5 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: antarr
4
+ buy_me_a_coffee: antarr
5
+ thanks_dev: antarr
@@ -13,14 +13,9 @@ jobs:
13
13
  strategy:
14
14
  fail-fast: false
15
15
  matrix:
16
- ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
17
- rails: ["5.2", "6.0", "6.1", "7.0", "7.1", "7.2"]
16
+ ruby: ["2.7", "3.0", "3.1", "3.2", "3.3", "3.4"]
17
+ rails: ["5.2", "6.0", "6.1", "7.0", "7.1", "7.2", "8.0", "8.1"]
18
18
  exclude:
19
- # Rails 7.0+ requires Ruby 2.7+, but 7.2 requires 3.1+
20
- - ruby: "2.7"
21
- rails: "7.2"
22
- - ruby: "3.0"
23
- rails: "7.2"
24
19
  # Rails 5.2 doesn't support Ruby 3.1+
25
20
  - ruby: "3.1"
26
21
  rails: "5.2"
@@ -28,11 +23,39 @@ jobs:
28
23
  rails: "5.2"
29
24
  - ruby: "3.3"
30
25
  rails: "5.2"
26
+ - ruby: "3.4"
27
+ rails: "5.2"
31
28
  # Rails 6.0 doesn't support Ruby 3.2+
32
29
  - ruby: "3.2"
33
30
  rails: "6.0"
34
31
  - ruby: "3.3"
35
32
  rails: "6.0"
33
+ - ruby: "3.4"
34
+ rails: "6.0"
35
+ # Rails 6.1 doesn't support Ruby 3.4 (mutex_m removed from stdlib)
36
+ - ruby: "3.4"
37
+ rails: "6.1"
38
+ # Rails 7.0 doesn't support Ruby 3.4 (mutex_m removed from stdlib)
39
+ - ruby: "3.4"
40
+ rails: "7.0"
41
+ # Rails 7.2+ requires Ruby 3.1+
42
+ - ruby: "2.7"
43
+ rails: "7.2"
44
+ - ruby: "3.0"
45
+ rails: "7.2"
46
+ # Rails 8.0+ requires Ruby 3.2+
47
+ - ruby: "2.7"
48
+ rails: "8.0"
49
+ - ruby: "3.0"
50
+ rails: "8.0"
51
+ - ruby: "3.1"
52
+ rails: "8.0"
53
+ - ruby: "2.7"
54
+ rails: "8.1"
55
+ - ruby: "3.0"
56
+ rails: "8.1"
57
+ - ruby: "3.1"
58
+ rails: "8.1"
36
59
 
37
60
  env:
38
61
  RAILS_VERSION: ${{ matrix.rails }}
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  /vendor
13
+ CLAUDE.md
14
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ require:
5
+ - rubocop-rspec
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.6
9
+ NewCops: enable
10
+
11
+ Layout/LineLength:
12
+ Max: 250
13
+
14
+ RSpec/MessageSpies:
15
+ Enabled: false
16
+
17
+ RSpec/VerifiedDoubles:
18
+ Enabled: false
19
+
20
+ RSpec/ExampleLength:
21
+ Max: 25
22
+
23
+ RSpec/MultipleExpectations:
24
+ Max: 5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Improved
6
+ - **SQL syntax highlighting** -- SQL code blocks in tables now feature a dark-themed syntax highlighter with distinct colors for keywords, functions, strings, numbers, operators, identifiers, and placeholders (Catppuccin Mocha palette)
7
+ - **Table visual hierarchy** -- redesigned table headers (uppercase, thicker bottom border, rounded top corners), improved row hover states (blue tint), cleaner alternating row colors, removed vertical cell borders
8
+ - **Numeric column formatting** -- right-aligned with monospace tabular-nums font for easy scanning; duration values color-coded green/amber/red by severity
9
+ - **Overall dashboard polish** -- more generous cell padding, improved inline `code` tag styling, added `mg-badge-success` variant
10
+ - **Tab persistence** -- active tab is remembered across page reloads via URL hash
11
+
12
+ ### Fixed
13
+ - **Unused indexes SQL error on MySQL 8.0+** -- `reads` and `writes` are reserved words and now use backtick quoting
14
+
15
+ ### Added
16
+ - **Dark theme** -- auto-detects system preference, manual toggle via sun/moon button, persisted in localStorage
17
+ - **Tables tab** -- renamed from "Table Sizes", now shows engine, collation, auto-increment, last updated, and accurate row counts via `COUNT(*)`
18
+ - **Optimize suggestions** -- tables with >10% fragmentation are flagged with an optimize badge
19
+
20
+ ## 0.2.0
21
+
22
+ - **Dashboard-first redesign** -- new default landing page with server health, top slow queries, top expensive queries, and index alert badges
23
+ - **Query Explorer** -- merged Visual Builder and SQL Query into one tab with a mode toggle
24
+ - **Suggested migrations** -- duplicate and unused index tabs generate timestamped Rails migrations with copy-to-clipboard
25
+ - **Install generator** -- `rails generate mysql_genius:install` creates initializer and mounts the engine
26
+ - **RuboCop** -- added rubocop-shopify and rubocop-rspec, enforced across the codebase
27
+ - **CI matrix** -- added Ruby 3.4, Rails 8.0 and 8.1; excluded incompatible Ruby 3.4 + Rails 6.1/7.0 combos
28
+ - **Smarter AI prompts** -- schema review now includes primary keys and Rails-aware context (no foreign key constraint recommendations, recommends indexes on FK columns instead)
29
+ - **SSL fix** -- explicit CA certificate file for AI API requests
30
+ - Tab reorder: Dashboard, Slow Queries, Query Stats, Server, Table Sizes, Unused Indexes, Duplicate Indexes, Query Explorer, AI Tools
31
+ - Dashboard links to Server tab for full details
32
+ - Clipboard fallback for non-HTTPS environments
33
+ - Gemspec description updated to lead with monitoring features
34
+
3
35
  ## 0.1.0
4
36
 
5
37
  - Initial release
data/Gemfile CHANGED
@@ -1,15 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
5
7
  if ENV["RAILS_VERSION"]
6
8
  rails_version = ENV["RAILS_VERSION"]
7
- gem "railties", "~> #{rails_version}.0"
8
- gem "activerecord", "~> #{rails_version}.0"
9
9
  gem "actionpack", "~> #{rails_version}.0"
10
+ gem "activerecord", "~> #{rails_version}.0"
11
+ gem "railties", "~> #{rails_version}.0"
10
12
  end
11
13
 
12
14
  group :development, :test do
13
15
  gem "rake"
14
16
  gem "rspec", "~> 3.0"
17
+ gem "rubocop"
18
+ gem "rubocop-shopify"
19
+ gem "rubocop-rspec"
15
20
  end
data/README.md CHANGED
@@ -1,40 +1,51 @@
1
1
  # MySQLGenius
2
2
 
3
- A MySQL performance dashboard and query explorer for Rails, inspired by [PgHero](https://github.com/ankane/pghero). If you've used PgHero for PostgreSQL and wished something similar existed for MySQL -- this is it, with AI-powered query suggestions and optimization on top.
3
+ A AI powered MySQL dashboard and build to help you optimize your database for maximum performance, inspired by [PgHero](https://github.com/ankane/pghero).
4
4
 
5
5
  ## Screenshots
6
6
 
7
- ### Visual Builder
8
- Build queries visually -- select tables, pick columns, add type-aware filters, and sort results without writing SQL.
7
+ ### Dashboard
9
8
 
10
- ![Visual Builder](docs/screenshots/visual_builder.png)
9
+ At-a-glance server health, top slow queries, most expensive queries, and index alerts.
11
10
 
12
- ### SQL Query with AI Assistant
13
- Write raw SQL or describe what you want in plain English and let the AI generate the query for you.
11
+ ![Dashboard](docs/screenshots/dashboard.png)
14
12
 
15
- ![SQL Query](docs/screenshots/sql_query.png)
13
+ ### Slow Queries
16
14
 
17
- ### Duplicate Index Detection
18
- Find redundant indexes whose columns are a left-prefix of another index, with ready-to-run `DROP INDEX` statements.
15
+ SELECT queries exceeding the configured threshold, captured via ActiveSupport notifications and Redis.
19
16
 
20
- ![Duplicate Indexes](docs/screenshots/duplicate_indexes.png)
17
+ ### Query Stats
18
+
19
+ Top queries from `performance_schema` sorted by total time, with call counts, avg/max time, and rows examined.
20
+
21
+ ![Query Stats](docs/screenshots/query_stats.png)
22
+
23
+ ### Server Dashboard
24
+
25
+ Server health: version, connections, InnoDB buffer pool, and query activity with AI-powered diagnostics.
26
+
27
+ ![Server](docs/screenshots/server.png)
21
28
 
22
29
  ### Table Sizes
30
+
23
31
  View row counts, data size, index size, fragmentation, and a visual size chart for every table.
24
32
 
25
33
  ![Table Sizes](docs/screenshots/table_sizes.png)
26
34
 
27
- ### Query Stats
28
- Top queries from `performance_schema` sorted by total time, with call counts, avg/max time, and rows examined.
35
+ ### Duplicate Index Detection
29
36
 
30
- ![Query Stats](docs/screenshots/query_stats.png)
37
+ Find redundant indexes whose columns are a left-prefix of another index, with ready-to-run `DROP INDEX` statements.
31
38
 
32
- ### Server Dashboard
33
- At-a-glance server health: version, connections, InnoDB buffer pool, and query activity with AI-powered diagnostics.
39
+ ![Duplicate Indexes](docs/screenshots/duplicate_indexes.png)
34
40
 
35
- ![Server](docs/screenshots/server.png)
41
+ ### Query Explorer
42
+
43
+ Build queries visually or write raw SQL. Optional AI assistant generates queries from plain English descriptions.
44
+
45
+ ![Query Explorer](docs/screenshots/query_explore.png)
36
46
 
37
47
  ### AI Tools
48
+
38
49
  Schema review that finds anti-patterns -- missing primary keys, nullable foreign keys, inappropriate column types, and more.
39
50
 
40
51
  ![AI Tools](docs/screenshots/ai_tools.png)
@@ -77,7 +88,7 @@ gem "mysql_genius", github: "antarr/mysql_genius"
77
88
 
78
89
  Then run:
79
90
 
80
- ```
91
+ ```bash
81
92
  bundle install
82
93
  ```
83
94
 
@@ -215,25 +226,24 @@ When AI is not configured, the AI Assistant panel and optimization buttons are h
215
226
 
216
227
  ## Usage
217
228
 
218
- Visit `/mysql_genius` in your browser. The dashboard has five tabs:
229
+ Visit `/mysql_genius` in your browser. The dashboard loads automatically with an overview of your database health.
219
230
 
220
- ### Visual Builder
221
- Select a table, pick columns, add type-aware filters (dates get date pickers, booleans get dropdowns), add sort orders, and run queries -- no SQL knowledge required. The generated SQL is shown and synced with the SQL tab.
231
+ ### Dashboard
222
232
 
223
- ### SQL Query
224
- Write raw SQL directly. The optional AI Assistant lets you describe what you want in plain English and generates a query. AI-generated queries are synced back to the Visual Builder for further refinement.
233
+ The default landing page shows server health cards, top 5 slow queries, top 5 most expensive queries (from performance_schema), and index alert badges for duplicate and unused indexes. Each section links to its detailed tab.
225
234
 
226
- ### Slow Queries
227
- View slow SELECT queries captured from your application in real time. Each slow query can be:
228
- - **Explained** -- run EXPLAIN to see the execution plan (bypasses blocked table restrictions)
229
- - **Used** -- copy to the SQL tab for editing and re-running
230
- - **Optimized** -- get AI-powered optimization suggestions with specific index and rewrite recommendations
235
+ ### Query Explorer
231
236
 
232
- ### Duplicate Indexes
233
- Scans all tables for redundant indexes -- indexes whose columns are a left-prefix of another index on the same table. Shows the `ALTER TABLE ... DROP INDEX` statement for each duplicate, ready to copy and run.
237
+ Combines the visual query builder and raw SQL editor in one tab. Toggle between Visual mode (point-and-click with column selection, filters, and ordering) and SQL mode (raw SQL with optional AI assistant). Generated SQL syncs between modes.
234
238
 
235
- ### Table Sizes
236
- Displays every table sorted by total size, with columns for estimated row count, data size, index size, total size, and fragmented space. Includes a visual size bar for quick comparison.
239
+ ### Monitoring Tabs
240
+
241
+ - **Slow Queries** -- slow SELECT queries captured from your application in real time, with Explain and Optimize actions
242
+ - **Query Stats** -- top queries from `performance_schema` sorted by total time, avg time, calls, or rows examined
243
+ - **Server** -- connections, InnoDB buffer pool, query activity, with AI-powered diagnostics
244
+ - **Table Sizes** -- row counts, data size, index size, fragmentation for all tables
245
+ - **Unused Indexes** -- indexes with zero reads since server restart
246
+ - **Duplicate Indexes** -- redundant indexes with ready-to-run DROP statements
237
247
 
238
248
  ## Configuration Reference
239
249
 
@@ -264,16 +274,18 @@ Tested against:
264
274
 
265
275
  | Rails | Ruby |
266
276
  |-------|------|
267
- | 5.2 | 2.6, 2.7, 3.0 |
268
- | 6.0 | 2.6, 2.7, 3.0, 3.1 |
269
- | 6.1 | 2.6, 2.7, 3.0, 3.1, 3.2, 3.3 |
277
+ | 5.2 | 2.7, 3.0 |
278
+ | 6.0 | 2.7, 3.0, 3.1 |
279
+ | 6.1 | 2.7, 3.0, 3.1, 3.2, 3.3 |
270
280
  | 7.0 | 2.7, 3.0, 3.1, 3.2, 3.3 |
271
- | 7.1 | 2.7, 3.0, 3.1, 3.2, 3.3 |
272
- | 7.2 | 3.1, 3.2, 3.3 |
281
+ | 7.1 | 2.7, 3.0, 3.1, 3.2, 3.3, 3.4 |
282
+ | 7.2 | 3.1, 3.2, 3.3, 3.4 |
283
+ | 8.0 | 3.2, 3.3, 3.4 |
284
+ | 8.1 | 3.2, 3.3, 3.4 |
273
285
 
274
286
  ## Development
275
287
 
276
- ```
288
+ ```bash
277
289
  git clone https://github.com/antarr/mysql_genius.git
278
290
  cd mysql_genius
279
291
  bin/setup
@@ -282,7 +294,7 @@ bundle exec rspec
282
294
 
283
295
  To test against a specific Rails version:
284
296
 
285
- ```
297
+ ```bash
286
298
  RAILS_VERSION=6.1 bundle update && bundle exec rspec
287
299
  ```
288
300
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec