Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions go/mysql/flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const (
// mysql8VersionPrefix is the prefix for 8.x mysql version, such as 8.0.19,
// but also newer ones like 8.4.0.
mysql8VersionPrefix = "8."
// mysql9VersionPrefix is the prefix for 9.x mysql version, such as 9.0.0,
// 9.1.0, 9.2.0, etc.
mysql9VersionPrefix = "9."
)

// flavor is the abstract interface for a flavor.
Expand Down Expand Up @@ -200,6 +203,9 @@ func GetFlavor(serverVersion string, flavorFunc func(serverVersion string) flavo
} else {
f = mysqlFlavor8Legacy{mysqlFlavorLegacy{mysqlFlavor{serverVersion: serverVersion}}}
}
case strings.HasPrefix(serverVersion, mysql9VersionPrefix):
// MySQL 9.x uses the most modern flavor (mysqlFlavor82)
f = mysqlFlavor82{mysqlFlavor{serverVersion: serverVersion}}
default:
// If unknown, return the most basic flavor: MySQL 57.
f = mysqlFlavor57{mysqlFlavorLegacy{mysqlFlavor{serverVersion: serverVersion}}}
Expand Down
173 changes: 173 additions & 0 deletions go/mysql/flavor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ func TestServerVersionCapableOf(t *testing.T) {
capability: capabilities.CheckConstraintsCapability,
isCapable: true,
},
{
// MySQL 9.0.0 should support modern capabilities
version: "9.0.0",
capability: capabilities.InstantDDLFlavorCapability,
isCapable: true,
},
{
// MySQL 9.1.0 should support transactional GTID executed
version: "9.1.0",
capability: capabilities.TransactionalGtidExecutedFlavorCapability,
isCapable: true,
},
{
// MySQL 9.0.5 should support check constraints
version: "9.0.5",
capability: capabilities.CheckConstraintsCapability,
isCapable: true,
},
{
// MySQL 9.2.1-log should support performance schema data locks
version: "9.2.1-log",
capability: capabilities.PerformanceSchemaDataLocksTableCapability,
isCapable: true,
},
}
for _, tc := range testcases {
name := fmt.Sprintf("%s %v", tc.version, tc.capability)
Expand All @@ -129,3 +153,152 @@ func TestServerVersionCapableOf(t *testing.T) {
})
}
}

func TestGetFlavor(t *testing.T) {
testcases := []struct {
version string
expectedType string
description string
}{
// MySQL 5.7.x versions should get mysqlFlavor57
{
version: "5.7.29",
expectedType: "mysqlFlavor57",
description: "MySQL 5.7 should use mysqlFlavor57",
},
{
version: "5.7.38-log",
expectedType: "mysqlFlavor57",
description: "MySQL 5.7 with suffix should use mysqlFlavor57",
},
// MySQL 8.0.x versions with different capabilities
{
version: "8.0.11",
expectedType: "mysqlFlavor8Legacy",
description: "MySQL 8.0.11 should use mysqlFlavor8Legacy (no replica terminology)",
},
{
version: "8.0.22",
expectedType: "mysqlFlavor8Legacy",
description: "MySQL 8.0.22 should use mysqlFlavor8Legacy (no replica terminology, < 8.0.26)",
},
{
version: "8.0.26",
expectedType: "mysqlFlavor8",
description: "MySQL 8.0.26 should use mysqlFlavor8 (has replica terminology, < 8.2.0)",
},
{
version: "8.1.0",
expectedType: "mysqlFlavor8",
description: "MySQL 8.1.0 should use mysqlFlavor8 (has replica terminology, < 8.2.0)",
},
{
version: "8.2.0",
expectedType: "mysqlFlavor82",
description: "MySQL 8.2.0 should use mysqlFlavor82",
},
{
version: "8.3.0",
expectedType: "mysqlFlavor82",
description: "MySQL 8.3.0 should use mysqlFlavor82",
},
{
version: "8.0.30-log",
expectedType: "mysqlFlavor8",
description: "MySQL 8.0.30 with suffix should use mysqlFlavor8 (has replica terminology, < 8.2.0)",
},
// MySQL 9.x versions should get mysqlFlavor82
{
version: "9.0.0",
expectedType: "mysqlFlavor82",
description: "MySQL 9.0.0 should use mysqlFlavor82",
},
{
version: "9.1.0",
expectedType: "mysqlFlavor82",
description: "MySQL 9.1.0 should use mysqlFlavor82",
},
{
version: "9.0.5-log",
expectedType: "mysqlFlavor82",
description: "MySQL 9.0.5 with suffix should use mysqlFlavor82",
},
{
version: "9.2.1-debug",
expectedType: "mysqlFlavor82",
description: "MySQL 9.2.1 with debug suffix should use mysqlFlavor82",
},
{
version: "9.10.15",
expectedType: "mysqlFlavor82",
description: "MySQL 9.10.15 should use mysqlFlavor82",
},
// MariaDB versions
{
version: "5.5.5-10.1.48-MariaDB",
expectedType: "mariadbFlavor101",
description: "MariaDB 10.1 with replication hack prefix should use mariadbFlavor101",
},
{
version: "10.1.48-MariaDB",
expectedType: "mariadbFlavor101",
description: "MariaDB 10.1 should use mariadbFlavor101",
},
{
version: "10.2.0-MariaDB",
expectedType: "mariadbFlavor102",
description: "MariaDB 10.2 should use mariadbFlavor102",
},
{
version: "10.5.15-MariaDB-log",
expectedType: "mariadbFlavor102",
description: "MariaDB 10.5 with suffix should use mariadbFlavor102",
},
// Default/unknown versions should get mysqlFlavor57
{
version: "5.6.45",
expectedType: "mysqlFlavor57",
description: "MySQL 5.6 should default to mysqlFlavor57",
},
{
version: "unknown-version",
expectedType: "mysqlFlavor57",
description: "Unknown version should default to mysqlFlavor57",
},
{
version: "4.1.22",
expectedType: "mysqlFlavor57",
description: "Very old MySQL version should default to mysqlFlavor57",
},
}

for _, tc := range testcases {
t.Run(fmt.Sprintf("%s_%s", tc.version, tc.expectedType), func(t *testing.T) {
flavor, _, _ := GetFlavor(tc.version, nil)

// Check the flavor type matches expected
switch tc.expectedType {
case "mysqlFlavor57":
_, ok := flavor.(mysqlFlavor57)
assert.True(t, ok, "Expected mysqlFlavor57 for version %s, but got %T. %s", tc.version, flavor, tc.description)
case "mysqlFlavor8Legacy":
_, ok := flavor.(mysqlFlavor8Legacy)
assert.True(t, ok, "Expected mysqlFlavor8Legacy for version %s, but got %T. %s", tc.version, flavor, tc.description)
case "mysqlFlavor8":
_, ok := flavor.(mysqlFlavor8)
assert.True(t, ok, "Expected mysqlFlavor8 for version %s, but got %T. %s", tc.version, flavor, tc.description)
case "mysqlFlavor82":
_, ok := flavor.(mysqlFlavor82)
assert.True(t, ok, "Expected mysqlFlavor82 for version %s, but got %T. %s", tc.version, flavor, tc.description)
case "mariadbFlavor101":
_, ok := flavor.(mariadbFlavor101)
assert.True(t, ok, "Expected mariadbFlavor101 for version %s, but got %T. %s", tc.version, flavor, tc.description)
case "mariadbFlavor102":
_, ok := flavor.(mariadbFlavor102)
assert.True(t, ok, "Expected mariadbFlavor102 for version %s, but got %T. %s", tc.version, flavor, tc.description)
default:
t.Errorf("Unknown expected type: %s", tc.expectedType)
}
})
}
}
Loading