fix(kingbase): omit invalid varchar length in exported DDL
This commit is contained in:
@@ -218,8 +218,9 @@ public final class DdlBuilder {
|
||||
private static String columnTypeSql(ColumnInfo column) {
|
||||
String type = column.getData_type();
|
||||
String normalized = type.toLowerCase(Locale.ROOT);
|
||||
if (isCharacterType(normalized) && column.getCharacter_maximum_length() != null) {
|
||||
return type + "(" + column.getCharacter_maximum_length() + ")";
|
||||
Integer characterLength = column.getCharacter_maximum_length();
|
||||
if (isCharacterType(normalized) && characterLength != null && characterLength > 0) {
|
||||
return type + "(" + characterLength + ")";
|
||||
}
|
||||
if (isNumericType(normalized) && column.getNumeric_precision() != null) {
|
||||
if (column.getNumeric_scale() != null) {
|
||||
|
||||
@@ -565,6 +565,23 @@ class KingbaseAgentTest extends JdbcFakeExecutionBehaviorTest {
|
||||
Assertions.assertFalse(ddl.contains("unknown metadata"), ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
void ddlOmitsUnknownCharacterLengthSentinel() {
|
||||
ColumnInfo unlimited = new ColumnInfo("display_name", "varchar", true, null, false, null, null, null, null, -1);
|
||||
|
||||
String ddl = DdlBuilder.buildTableDdl(
|
||||
"public",
|
||||
"accounts",
|
||||
Collections.singletonList(unlimited),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
true
|
||||
);
|
||||
|
||||
Assertions.assertTrue(ddl.contains("`display_name` varchar"), ddl);
|
||||
Assertions.assertFalse(ddl.contains("varchar(-1)"), ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularListIndexesIncludesPrimaryUniqueAndSecondaryIndexes() {
|
||||
List<String> sql = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user