(t *testing.T)
| 361 | } |
| 362 | |
| 363 | func TestCheckConstraintIdempotencyWithMySQLFormat(t *testing.T) { |
| 364 | // Test that CHECK constraints are idempotent when MySQL returns them with extra parens and charset |
| 365 | |
| 366 | // Parse as user would write it |
| 367 | stmt1, err := parser.ParseDDL("create table t (id int, check(`status` IN ('todo', 'in_progress')))", parser.ParserModeMysql) |
| 368 | assert.NoError(t, err) |
| 369 | ddl1 := stmt1.(*parser.DDL) |
| 370 | check1 := ddl1.TableSpec.Checks[0] |
| 371 | |
| 372 | // Parse as MySQL would return it (extra parens, charset prefix, lowercase) |
| 373 | stmt2, err := parser.ParseDDL("create table t (id int, check((`status` in (_utf8mb4'todo',_utf8mb4'in_progress'))))", parser.ParserModeMysql) |
| 374 | assert.NoError(t, err) |
| 375 | ddl2 := stmt2.(*parser.DDL) |
| 376 | check2 := ddl2.TableSpec.Checks[0] |
| 377 | |
| 378 | // Normalize both |
| 379 | normalized1 := normalizeCheckExpr(check1.Where.Expr, GeneratorModeMysql) |
| 380 | normalized2 := normalizeCheckExpr(check2.Where.Expr, GeneratorModeMysql) |
| 381 | |
| 382 | // Unwrap outermost parentheses (as done in areSameCheckDefinition) |
| 383 | normalized1 = unwrapOutermostParenExpr(normalized1) |
| 384 | normalized2 = unwrapOutermostParenExpr(normalized2) |
| 385 | |
| 386 | // Convert to strings |
| 387 | str1 := parser.String(normalized1) |
| 388 | str2 := parser.String(normalized2) |
| 389 | |
| 390 | t.Logf("Normalized 1 (user format): %s", str1) |
| 391 | t.Logf("Normalized 2 (MySQL format): %s", str2) |
| 392 | |
| 393 | // They should be the same (idempotent) |
| 394 | assert.Equal(t, str1, str2, "CHECK constraints should be idempotent despite MySQL's formatting") |
| 395 | } |
| 396 | |
| 397 | func TestAreSameForeignKeysConstraintOptionsNilVsDefault(t *testing.T) { |
| 398 | g := &Generator{mode: GeneratorModePostgres} |
nothing calls this directly
no test coverage detected