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

+20 -3
View File
@@ -156,8 +156,8 @@ var appSchema = []schemaColumn{
{"webui_audit", "zone", "varchar(255)"},
{"webui_audit", "record_id", "bigint"},
{"webui_audit", "target_user_id", "int"},
{"webui_audit", "before_value", "json"},
{"webui_audit", "after_value", "json"},
{"webui_audit", "before_value", "longtext"},
{"webui_audit", "after_value", "longtext"},
}
var appTables = []string{"webui_schema", "webui_users", "webui_sessions", "webui_zone_delegations", "webui_audit"}
@@ -189,7 +189,7 @@ func verifyAppSchema(ctx context.Context, q dbtx, t tableNames, log *slog.Logger
if !ok {
return fmt.Errorf("application schema: table %s has no column %s", table, c.column)
}
if got != c.columnType {
if !appColumnTypeMatches(got, c.columnType) {
return fmt.Errorf("application schema: column %s of table %s has type %s, expected %s", c.column, table, got, c.columnType)
}
}
@@ -200,6 +200,23 @@ func verifyAppSchema(ctx context.Context, q dbtx, t tableNames, log *slog.Logger
return nil
}
func appColumnTypeMatches(got, want string) bool {
switch want {
case "tinyint", "smallint", "int", "bigint":
// Older MySQL and MariaDB report a display width for signed integers.
// A trailing modifier such as UNSIGNED or ZEROFILL is still rejected.
if base, width, ok := strings.Cut(got, "("); ok && base == want {
width, closed := strings.CutSuffix(width, ")")
_, err := strconv.Atoi(width)
return closed && err == nil
}
case "longtext":
// The original MySQL schema stores the same audit payloads as native JSON.
return got == want || got == "json"
}
return got == want
}
func verifyAppForeignKeys(ctx context.Context, q dbtx, t tableNames) error {
var n int
err := q.QueryRowContext(ctx, "SELECT COUNT(DISTINCT TABLE_NAME, COLUMN_NAME) FROM information_schema.KEY_COLUMN_USAGE "+