Skip to content

Separate MySQL 5/8 features via replaceable driver architecture#5

Draft
atm-snag2 with Copilot wants to merge 5 commits into
masterfrom
copilot/separate-mysql5-features
Draft

Separate MySQL 5/8 features via replaceable driver architecture#5
atm-snag2 with Copilot wants to merge 5 commits into
masterfrom
copilot/separate-mysql5-features

Conversation

Copilot AI commented Nov 10, 2025

Copy link
Copy Markdown

Refactored monolithic driver into version-specific implementations to enable coexistence of MySQL 5 and MySQL 8 features with swappable driver classes.

Architecture

Factory pattern with automatic version detection:

  • Gratan::Driver now factory method that detects MySQL version and instantiates appropriate driver
  • Gratan::Driver::Base - common functionality (276 lines)
  • Gratan::Driver::MySQL5 - MySQL 5.6 (no SHOW CREATE USER)
  • Gratan::Driver::MySQL57 - MySQL 5.7 (SHOW CREATE USER support)
  • Gratan::Driver::MySQL8 - MySQL 8.0+ (ALTER USER, no PASSWORD() function)

Version-Specific Behavior

Feature MySQL 5.6 MySQL 5.7 MySQL 8.0
SHOW CREATE USER
Password management SET PASSWORD SET PASSWORD ALTER USER
PASSWORD() function ❌ (removed)

Usage

Automatic detection (default):

client = Gratan::Client.new(host: 'localhost', username: 'root')
# Detects version, instantiates MySQL5/MySQL57/MySQL8 driver

Manual override:

client = Gratan::Client.new(
  host: 'localhost',
  username: 'root',
  driver_class: Gratan::Driver::MySQL8
)

Changes

  • Reduced lib/gratan/driver.rb from 287 to 28 lines (now factory)
  • Extracted common logic to Base class
  • Version-specific implementations in separate files
  • Added 16 tests covering factory logic and integration
  • 100% backward compatible - no API changes

Net: +540 lines across 12 files

Original prompt

mysql8 系の機能と同居するために,mysql5 の機能を分離できる状態にしたい.実装クラスを入れ替えられるようにしたい


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 10, 2025 23:47
Co-authored-by: atm-snag2 <49628324+atm-snag2@users.noreply.github.com>
Co-authored-by: atm-snag2 <49628324+atm-snag2@users.noreply.github.com>
Co-authored-by: atm-snag2 <49628324+atm-snag2@users.noreply.github.com>
Co-authored-by: atm-snag2 <49628324+atm-snag2@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor to separate MySQL 5 features for compatibility Separate MySQL 5/8 features via replaceable driver architecture Nov 10, 2025
Copilot AI requested a review from atm-snag2 November 10, 2025 23:55
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.

2 participants