fix: support utf8mb4 across MySQL and MariaDB
Test / test (push) Canceled after 6m35s
Build and publish image / image (push) Successful in 13m42s

This commit is contained in:
bryanpedini committed 2026-11-20 15:14:28 +01:00
1 parent cce17c5fa4
commit d34894c9cd
28 files changed
+224 -121

No files matched your search

+30 -2
View File
@@ -30,7 +30,7 @@ const itRecordsDDL = "CREATE TABLE `%s`.`%srecords` (\n" +
" `content` TEXT,\n" +
" `record_type` VARCHAR(255) NOT NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci"
") ENGINE = INNODB DEFAULT CHARSET = utf8mb4"
var itAppGrants = []struct {
table string
@@ -94,6 +94,34 @@ type itDatabase struct {
root *sql.DB
}
// InnoDB on older servers only refreshes its lock metadata after 100 ms of idle time.
const itLockPollInterval = 150 * time.Millisecond
func (d *itDatabase) rowLockWaiting(ctx context.Context, suffix string) (bool, error) {
table := d.prefix + suffix
var waiting bool
err := d.root.QueryRowContext(ctx, "SELECT EXISTS (SELECT 1 FROM performance_schema.data_lock_waits w "+
"JOIN performance_schema.data_locks l ON l.ENGINE = w.ENGINE AND l.ENGINE_LOCK_ID = w.REQUESTING_ENGINE_LOCK_ID "+
"WHERE l.OBJECT_SCHEMA = ? AND l.OBJECT_NAME = ?)", d.name, table).Scan(&waiting)
if mysqlErrNumber(err) == 1146 {
// MySQL 5.7 and MariaDB expose the same wait through InnoDB metadata.
err = d.root.QueryRowContext(ctx, "SELECT EXISTS (SELECT 1 FROM information_schema.INNODB_LOCK_WAITS w "+
"JOIN information_schema.INNODB_LOCKS l ON l.LOCK_ID = w.REQUESTED_LOCK_ID "+
"WHERE l.LOCK_TABLE = ?)", "`"+d.name+"`.`"+table+"`").Scan(&waiting)
}
return waiting, err
}
func (d *itDatabase) hasCheckConstraint(t *testing.T, suffix string) bool {
t.Helper()
var tableName, ddl string
if err := d.root.QueryRow("SHOW CREATE TABLE `"+d.prefix+suffix+"`").Scan(&tableName, &ddl); err != nil {
t.Fatal(err)
}
// MySQL 5.7 parses CHECK constraints and omits them from the table.
return strings.Contains(ddl, "CHECK")
}
type itOptions struct {
prefix string
recordDDL string
@@ -121,7 +149,7 @@ func newITDatabase(t *testing.T, opts itOptions) *itDatabase {
t.Fatal(err)
}
}
exec("create database", "CREATE DATABASE `"+d.name+"` DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci")
exec("create database", "CREATE DATABASE `"+d.name+"` DEFAULT CHARSET = utf8mb4")
t.Cleanup(func() {
_, _ = admin.ExecContext(ctx, "DROP DATABASE IF EXISTS `"+d.name+"`")
_, _ = admin.ExecContext(ctx, "DROP USER IF EXISTS '"+d.appUser+"'@'%'")