Skip to content

Commit 4b1fe65

Browse files
committed
Standardize the test databases on MySQL 26.7
sqlc-test-setup pins the release it installs in one place, so the deb bundle it downloads, the version it accepts as already installed, and the docker-compose service all name MySQL 26.7, the same release goldeneye generates the dialect from and its gen workflow runs. The installed-version check compared the first digit of the major release, which would have called 26 older than 9; it compares the number now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012DTeySVan5NcA3RS6xxdUn
1 parent 3fb4c01 commit 4b1fe65

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

‎CLAUDE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ go run ./cmd/sqlc-test-setup install
2323
This will:
2424
- Configure the apt proxy (if `http_proxy` is set, e.g. in Claude Code remote environments)
2525
- Install PostgreSQL via apt
26-
- Download and install MySQL 9 from Oracle's deb bundle
26+
- Download and install MySQL 26.7 from Oracle's deb bundle
2727
- Resolve all dependencies automatically
2828
- Skip anything already installed
2929

@@ -181,7 +181,7 @@ The `docker-compose.yml` provides test databases:
181181
- Password: `mysecretpassword`
182182
- Database: `postgres`
183183

184-
- **MySQL 9** - Port 3306
184+
- **MySQL 26.7** - Port 3306
185185
- User: `root`
186186
- Password: `mysecretpassword`
187187
- Database: `dinotest`

‎cmd/sqlc-test-setup/main.go‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os/exec"
1212
"path/filepath"
1313
"runtime"
14+
"strconv"
1415
"strings"
1516
"time"
1617
)
@@ -86,7 +87,16 @@ func commandExists(name string) bool {
8687
return err == nil
8788
}
8889

89-
// isMySQLVersionOK checks if the mysqld --version output indicates MySQL 9+.
90+
// The MySQL release the tests run against. Everything that names a MySQL
91+
// version — the docker-compose service, the goldeneye dialect generator and
92+
// its gen workflow — is pinned to the same release.
93+
const (
94+
mysqlMajor = 26
95+
mysqlVersion = "26.7.0"
96+
)
97+
98+
// isMySQLVersionOK checks if the mysqld --version output indicates the
99+
// pinned major release or a later one.
90100
// Example version string: "/usr/sbin/mysqld Ver 8.0.44-0ubuntu0.24.04.2 ..."
91101
func isMySQLVersionOK(versionOutput string) bool {
92102
// Look for "Ver X.Y.Z" pattern
@@ -95,11 +105,11 @@ func isMySQLVersionOK(versionOutput string) bool {
95105
if strings.EqualFold(f, "Ver") && i+1 < len(fields) {
96106
ver := strings.Split(fields[i+1], ".")
97107
if len(ver) > 0 {
98-
major := strings.TrimLeft(ver[0], "0")
99-
if major == "" {
108+
major, err := strconv.Atoi(ver[0])
109+
if err != nil {
100110
return false
101111
}
102-
return major[0] >= '9'
112+
return major >= mysqlMajor
103113
}
104114
}
105115
}
@@ -302,18 +312,18 @@ func sha256File(path string) (string, error) {
302312
}
303313

304314
func installMySQL() error {
305-
log.Println("--- Installing MySQL 9 ---")
315+
log.Printf("--- Installing MySQL %s ---", mysqlVersion)
306316

307317
if commandExists("mysqld") {
308318
out, err := runOutput("mysqld", "--version")
309319
if err == nil {
310320
version := strings.TrimSpace(out)
311321
log.Printf("mysql is already installed: %s", version)
312322
if isMySQLVersionOK(version) {
313-
log.Println("mysql version is 9+, skipping installation")
323+
log.Printf("mysql version is %d+, skipping installation", mysqlMajor)
314324
return nil
315325
}
316-
log.Println("mysql version is too old, upgrading to MySQL 9")
326+
log.Printf("mysql version is too old, upgrading to MySQL %s", mysqlVersion)
317327
// Stop existing MySQL before upgrading
318328
_ = exec.Command("sudo", "service", "mysql", "stop").Run()
319329
_ = exec.Command("sudo", "pkill", "-f", "mysqld").Run()
@@ -322,20 +332,22 @@ func installMySQL() error {
322332
log.Println("removing old mysql packages")
323333
_ = run("sudo", "apt-get", "remove", "-y", "mysql-server", "mysql-client", "mysql-common",
324334
"mysql-server-core-*", "mysql-client-core-*")
325-
// Clear old data directory so MySQL 9 can initialize fresh
335+
// Clear old data directory so the new release can initialize fresh
326336
log.Println("clearing old mysql data directory")
327337
_ = run("sudo", "rm", "-rf", "/var/lib/mysql")
328338
_ = run("sudo", "mkdir", "-p", "/var/lib/mysql")
329339
_ = run("sudo", "chown", "mysql:mysql", "/var/lib/mysql")
330340
}
331341
}
332342

333-
bundleURL := "https://dev.mysql.com/get/Downloads/MySQL-9.1/mysql-server_9.1.0-1ubuntu24.04_amd64.deb-bundle.tar"
334-
bundleTar := "/tmp/mysql-server-bundle.tar"
335-
extractDir := "/tmp/mysql9"
343+
major, minor, _ := strings.Cut(mysqlVersion, ".")
344+
minor, _, _ = strings.Cut(minor, ".")
345+
bundleURL := fmt.Sprintf("https://dev.mysql.com/get/Downloads/MySQL-%s.%s/mysql-server_%s-1ubuntu24.04_amd64.deb-bundle.tar", major, minor, mysqlVersion)
346+
bundleTar := fmt.Sprintf("/tmp/mysql-server-%s-bundle.tar", mysqlVersion)
347+
extractDir := "/tmp/mysql-server-" + mysqlVersion
336348

337349
if _, err := os.Stat(bundleTar); err != nil {
338-
log.Printf("downloading MySQL 9 bundle from %s", bundleURL)
350+
log.Printf("downloading MySQL %s bundle from %s", mysqlVersion, bundleURL)
339351
if err := run("curl", "-L", "-o", bundleTar, bundleURL); err != nil {
340352
return fmt.Errorf("downloading mysql bundle: %w", err)
341353
}
@@ -378,7 +390,7 @@ func installMySQL() error {
378390
return fmt.Errorf("apt-get install -f: %w", err)
379391
}
380392

381-
log.Println("mysql 9 installed successfully")
393+
log.Printf("mysql %s installed successfully", mysqlVersion)
382394
return nil
383395
}
384396

‎docker-compose.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.8"
22
services:
33
mysql:
4-
image: "mysql:9"
4+
image: "mysql:26.7"
55
ports:
66
- "3306:3306"
77
restart: always

0 commit comments

Comments
 (0)