Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,49 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
rails: ["5.2", "6.0", "6.1", "7.0", "7.1", "7.2"]
ruby: ["2.7", "3.0", "3.1", "3.2", "3.3", "3.4"]
rails: ["5.2", "6.0", "6.1", "7.0", "7.1", "7.2", "8.0", "8.1"]
exclude:
# Rails 7.0+ requires Ruby 2.7+, but 7.2 requires 3.1+
- ruby: "2.7"
rails: "7.2"
- ruby: "3.0"
rails: "7.2"
# Rails 5.2 doesn't support Ruby 3.1+
- ruby: "3.1"
rails: "5.2"
- ruby: "3.2"
rails: "5.2"
- ruby: "3.3"
rails: "5.2"
- ruby: "3.4"
rails: "5.2"
# Rails 6.0 doesn't support Ruby 3.2+
- ruby: "3.2"
rails: "6.0"
- ruby: "3.3"
rails: "6.0"
- ruby: "3.4"
rails: "6.0"
# Rails 6.1 doesn't support Ruby 3.4 (mutex_m removed from stdlib)
- ruby: "3.4"
rails: "6.1"
# Rails 7.0 doesn't support Ruby 3.4 (mutex_m removed from stdlib)
- ruby: "3.4"
rails: "7.0"
# Rails 7.2+ requires Ruby 3.1+
- ruby: "2.7"
rails: "7.2"
- ruby: "3.0"
rails: "7.2"
# Rails 8.0+ requires Ruby 3.2+
- ruby: "2.7"
rails: "8.0"
- ruby: "3.0"
rails: "8.0"
- ruby: "3.1"
rails: "8.0"
- ruby: "2.7"
rails: "8.1"
- ruby: "3.0"
rails: "8.1"
- ruby: "3.1"
rails: "8.1"

env:
RAILS_VERSION: ${{ matrix.rails }}
Expand All @@ -51,3 +74,6 @@ jobs:

- name: Run specs
run: bundle exec rspec

- name: Run RuboCop
run: bundle exec rubocop
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
# rspec failure tracking
.rspec_status
/vendor
CLAUDE.md
Gemfile.lock
24 changes: 24 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
inherit_gem:
rubocop-shopify: rubocop.yml

require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.6
NewCops: enable

Layout/LineLength:
Max: 250

RSpec/MessageSpies:
Enabled: false

RSpec/VerifiedDoubles:
Enabled: false

RSpec/ExampleLength:
Max: 25

RSpec/MultipleExpectations:
Max: 5
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.2.0

- **Dashboard-first redesign** -- new default landing page with server health, top slow queries, top expensive queries, and index alert badges
- **Query Explorer** -- merged Visual Builder and SQL Query into one tab with a mode toggle
- **Suggested migrations** -- duplicate and unused index tabs generate timestamped Rails migrations with copy-to-clipboard
- **Install generator** -- `rails generate mysql_genius:install` creates initializer and mounts the engine
- **RuboCop** -- added rubocop-shopify and rubocop-rspec, enforced across the codebase
- **CI matrix** -- added Ruby 3.4, Rails 8.0 and 8.1; excluded incompatible Ruby 3.4 + Rails 6.1/7.0 combos
- **SSL fix** -- explicit CA certificate file for AI API requests
- Tab reorder: Dashboard, Slow Queries, Query Stats, Server, Table Sizes, Unused Indexes, Duplicate Indexes, Query Explorer, AI Tools
- Dashboard links to Server tab for full details
- Clipboard fallback for non-HTTPS environments
- Gemspec description updated to lead with monitoring features

## 0.1.0

- Initial release
Expand Down
9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec

if ENV["RAILS_VERSION"]
rails_version = ENV["RAILS_VERSION"]
gem "railties", "~> #{rails_version}.0"
gem "activerecord", "~> #{rails_version}.0"
gem "actionpack", "~> #{rails_version}.0"
gem "activerecord", "~> #{rails_version}.0"
gem "railties", "~> #{rails_version}.0"
end

group :development, :test do
gem "rake"
gem "rspec", "~> 3.0"
gem "rubocop"
gem "rubocop-shopify"
gem "rubocop-rspec"
end
86 changes: 49 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,48 @@ A MySQL performance dashboard and query explorer for Rails, inspired by [PgHero]

## Screenshots

### Visual Builder
Build queries visually -- select tables, pick columns, add type-aware filters, and sort results without writing SQL.
### Dashboard

![Visual Builder](docs/screenshots/visual_builder.png)
At-a-glance server health, top slow queries, most expensive queries, and index alerts.

### SQL Query with AI Assistant
Write raw SQL or describe what you want in plain English and let the AI generate the query for you.
![Dashboard](docs/screenshots/dashboard.png)

![SQL Query](docs/screenshots/sql_query.png)
### Slow Queries

### Duplicate Index Detection
Find redundant indexes whose columns are a left-prefix of another index, with ready-to-run `DROP INDEX` statements.
SELECT queries exceeding the configured threshold, captured via ActiveSupport notifications and Redis.

![Duplicate Indexes](docs/screenshots/duplicate_indexes.png)
### Query Stats

Top queries from `performance_schema` sorted by total time, with call counts, avg/max time, and rows examined.

![Query Stats](docs/screenshots/query_stats.png)

### Server Dashboard

Server health: version, connections, InnoDB buffer pool, and query activity with AI-powered diagnostics.

![Server](docs/screenshots/server.png)

### Table Sizes

View row counts, data size, index size, fragmentation, and a visual size chart for every table.

![Table Sizes](docs/screenshots/table_sizes.png)

### Query Stats
Top queries from `performance_schema` sorted by total time, with call counts, avg/max time, and rows examined.
### Duplicate Index Detection

![Query Stats](docs/screenshots/query_stats.png)
Find redundant indexes whose columns are a left-prefix of another index, with ready-to-run `DROP INDEX` statements.

### Server Dashboard
At-a-glance server health: version, connections, InnoDB buffer pool, and query activity with AI-powered diagnostics.
![Duplicate Indexes](docs/screenshots/duplicate_indexes.png)

![Server](docs/screenshots/server.png)
### Query Explorer

Build queries visually or write raw SQL. Optional AI assistant generates queries from plain English descriptions.

![Query Explorer](docs/screenshots/query_explore.png)

### AI Tools

Schema review that finds anti-patterns -- missing primary keys, nullable foreign keys, inappropriate column types, and more.

![AI Tools](docs/screenshots/ai_tools.png)
Expand Down Expand Up @@ -77,7 +88,7 @@ gem "mysql_genius", github: "antarr/mysql_genius"

Then run:

```
```bash
bundle install
```

Expand Down Expand Up @@ -215,25 +226,24 @@ When AI is not configured, the AI Assistant panel and optimization buttons are h

## Usage

Visit `/mysql_genius` in your browser. The dashboard has five tabs:
Visit `/mysql_genius` in your browser. The dashboard loads automatically with an overview of your database health.

### Visual Builder
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.
### Dashboard

### SQL Query
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.
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.

### Slow Queries
View slow SELECT queries captured from your application in real time. Each slow query can be:
- **Explained** -- run EXPLAIN to see the execution plan (bypasses blocked table restrictions)
- **Used** -- copy to the SQL tab for editing and re-running
- **Optimized** -- get AI-powered optimization suggestions with specific index and rewrite recommendations
### Query Explorer

### Duplicate Indexes
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.
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.

### Table Sizes
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.
### Monitoring Tabs

- **Slow Queries** -- slow SELECT queries captured from your application in real time, with Explain and Optimize actions
- **Query Stats** -- top queries from `performance_schema` sorted by total time, avg time, calls, or rows examined
- **Server** -- connections, InnoDB buffer pool, query activity, with AI-powered diagnostics
- **Table Sizes** -- row counts, data size, index size, fragmentation for all tables
- **Unused Indexes** -- indexes with zero reads since server restart
- **Duplicate Indexes** -- redundant indexes with ready-to-run DROP statements

## Configuration Reference

Expand Down Expand Up @@ -264,16 +274,18 @@ Tested against:

| Rails | Ruby |
|-------|------|
| 5.2 | 2.6, 2.7, 3.0 |
| 6.0 | 2.6, 2.7, 3.0, 3.1 |
| 6.1 | 2.6, 2.7, 3.0, 3.1, 3.2, 3.3 |
| 5.2 | 2.7, 3.0 |
| 6.0 | 2.7, 3.0, 3.1 |
| 6.1 | 2.7, 3.0, 3.1, 3.2, 3.3 |
| 7.0 | 2.7, 3.0, 3.1, 3.2, 3.3 |
| 7.1 | 2.7, 3.0, 3.1, 3.2, 3.3 |
| 7.2 | 3.1, 3.2, 3.3 |
| 7.1 | 2.7, 3.0, 3.1, 3.2, 3.3, 3.4 |
| 7.2 | 3.1, 3.2, 3.3, 3.4 |
| 8.0 | 3.2, 3.3, 3.4 |
| 8.1 | 3.2, 3.3, 3.4 |

## Development

```
```bash
git clone https://github.com/antarr/mysql_genius.git
cd mysql_genius
bin/setup
Expand All @@ -282,7 +294,7 @@ bundle exec rspec

To test against a specific Rails version:

```
```bash
RAILS_VERSION=6.1 bundle update && bundle exec rspec
```

Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
Loading
Loading