fix: support utf8mb4 across MySQL and MariaDB
This commit is contained in:
1 parent
cce17c5fa4
commit
d34894c9cd
28 files changed
+224
-121
No files matched your search
+20
-5
@@ -144,7 +144,7 @@ func TestIntegrationMigrations(t *testing.T) {
|
||||
t.Fatal(version, err)
|
||||
}
|
||||
for _, table := range []string{"coredns_webui_schema", "coredns_webui_users", "coredns_webui_sessions", "coredns_webui_zone_delegations", "coredns_webui_audit"} {
|
||||
if d.count(t, "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND TABLE_COLLATION = 'utf8mb4_0900_ai_ci' AND ENGINE = 'InnoDB'", table) != 1 {
|
||||
if d.count(t, "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND TABLE_COLLATION IN (SELECT COLLATION_NAME FROM information_schema.COLLATIONS WHERE CHARACTER_SET_NAME = 'utf8mb4') AND ENGINE = 'InnoDB'", table) != 1 {
|
||||
t.Fatalf("%s missing", table)
|
||||
}
|
||||
}
|
||||
@@ -163,8 +163,10 @@ func TestIntegrationMigrations(t *testing.T) {
|
||||
if n := d.count(t, "SELECT `version` FROM `coredns_webui_schema` WHERE `id` = 1"); n != 2 {
|
||||
t.Fatalf("version %d", n)
|
||||
}
|
||||
if _, err := d.root.Exec("INSERT INTO `coredns_webui_schema` (`id`, `version`) VALUES (2, 1)"); err == nil {
|
||||
t.Fatal("second schema row accepted")
|
||||
if d.hasCheckConstraint(t, "webui_schema") {
|
||||
if _, err := d.root.Exec("INSERT INTO `coredns_webui_schema` (`id`, `version`) VALUES (2, 1)"); err == nil {
|
||||
t.Fatal("second schema row accepted")
|
||||
}
|
||||
}
|
||||
d.rootExec(t, "UPDATE `coredns_webui_schema` SET `version` = 3")
|
||||
if err := migrateDatabase(ctx, db, tn, discardLogger()); err == nil || !strings.Contains(err.Error(), "newer") {
|
||||
@@ -172,6 +174,16 @@ func TestIntegrationMigrations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationAcceptsExistingJSONAuditColumns(t *testing.T) {
|
||||
t.Parallel()
|
||||
d := newITDatabase(t, itOptions{prefix: "legacy_"})
|
||||
db, tn := d.migrated(t)
|
||||
d.rootExec(t, tn.sql("ALTER TABLE {audit} MODIFY before_value JSON NULL, MODIFY after_value JSON NULL"))
|
||||
if err := migrateDatabase(t.Context(), db, tn, discardLogger()); err != nil {
|
||||
t.Fatalf("existing JSON audit columns: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationAuditRecordIDMigration(t *testing.T) {
|
||||
const prefix = "audit_id_"
|
||||
migrations, err := loadMigrations(migrationFiles, prefix)
|
||||
@@ -350,8 +362,11 @@ func TestIntegrationForeignKeys(t *testing.T) {
|
||||
if _, err := d.root.Exec("DELETE FROM `coredns_webui_users` WHERE `id` = ?", u2.ID); mysqlErrNumber(err) != 1451 {
|
||||
t.Fatalf("referenced user deleted: %v", err)
|
||||
}
|
||||
if _, err := d.root.Exec("INSERT INTO `coredns_webui_users` (`username`, `role`, `password_hash`, `created_at`, `updated_at`) VALUES ('x', 'root', 'h', NOW(6), NOW(6))"); mysqlErrNumber(err) != 3819 {
|
||||
t.Fatalf("role check: %v", err)
|
||||
if d.hasCheckConstraint(t, "webui_users") {
|
||||
_, err := d.root.Exec("INSERT INTO `coredns_webui_users` (`username`, `role`, `password_hash`, `created_at`, `updated_at`) VALUES ('x', 'root', 'h', NOW(6), NOW(6))")
|
||||
if n := mysqlErrNumber(err); n != 3819 && n != 4025 {
|
||||
t.Fatalf("role check: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user