Skip to content

Add multi-database support#2

Closed
antarr wants to merge 24 commits into
mainfrom
multiple-database
Closed

Add multi-database support#2
antarr wants to merge 24 commits into
mainfrom
multiple-database

Conversation

@antarr

@antarr antarr commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Auto-detect MySQL/MariaDB databases from Rails database.yml (supports Rails 5.2-8.1)
  • Per-database settings via config/mysql_genius.yml with environment-specific overrides
  • Database switcher dropdown in the dashboard header (hidden in single-DB setups)
  • URL-scoped routing: /mysql_genius/analytics/, /mysql_genius/primary/execute, etc.
  • config.database(:name) Ruby DSL for per-database overrides in the initializer
  • Full backward compatibility: single-database setups work without any changes

Per-database configurable settings

blocked_tables, masked_column_patterns, featured_tables, default_columns, max_row_limit, default_row_limit, query_timeout_ms

Architecture

  • DatabaseConfig -- per-database settings with fallback to global Configuration
  • DatabaseRegistry -- YAML loading, auto-detection from Rails configs, version-aware (5.2-8.1)
  • BaseController -- resolve_database! before_action, connection helper replacing 25+ hardcoded ActiveRecord::Base.connection calls
  • AI services -- accept connection: keyword so queries run against the correct database

New files

File Purpose
lib/mysql_genius/database_config.rb Per-database settings with fallback
lib/mysql_genius/database_registry.rb YAML loading & auto-detection
spec/mysql_genius/database_config_spec.rb 8 examples
spec/mysql_genius/database_registry_spec.rb 11 examples

Test plan

  • 94 examples, 0 failures
  • RuboCop clean (0 offenses)
  • Test with a multi-database Rails app (primary + analytics)
  • Verify single-database backward compat (no YAML, existing setup)
  • Verify database switcher dropdown appears only in multi-DB mode
  • Verify URL routing: /mysql_genius/, /mysql_genius/primary/, /mysql_genius/analytics/
  • Verify YAML config loading with environment override

antarr added 24 commits April 10, 2026 07:32
- Add ConnectionPool module for managing per-database connections
  with named AR base classes (Rails 5.2 compat)
- Lazy-build DatabaseRegistry on first access instead of boot-time
  to survive Rails development-mode class reloading
- Fall back to database key name when connection_spec is nil
- Fix unused indexes SQL error (reads/writes are reserved in MySQL 8.0+)
@antarr

antarr commented Apr 13, 2026

Copy link
Copy Markdown
Owner Author

Closing — superseded by Phase 2c desktop profile switching. The Rails adapter uses the host app's ActiveRecord connection and doesn't need its own multi-database management.

@antarr antarr closed this Apr 13, 2026
@antarr antarr deleted the multiple-database branch May 31, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant