fix(kingbase): omit invalid varchar length in exported DDL
This commit is contained in:
2 files changed
+20
-2
No files matched your search
@@ -218,8 +218,9 @@ public final class DdlBuilder {
|
|||||||
private static String columnTypeSql(ColumnInfo column) {
|
private static String columnTypeSql(ColumnInfo column) {
|
||||||
String type = column.getData_type();
|
String type = column.getData_type();
|
||||||
String normalized = type.toLowerCase(Locale.ROOT);
|
String normalized = type.toLowerCase(Locale.ROOT);
|
||||||
if (isCharacterType(normalized) && column.getCharacter_maximum_length() != null) {
|
Integer characterLength = column.getCharacter_maximum_length();
|
||||||
return type + "(" + column.getCharacter_maximum_length() + ")";
|
if (isCharacterType(normalized) && characterLength != null && characterLength > 0) {
|
||||||
|
return type + "(" + characterLength + ")";
|
||||||
}
|
}
|
||||||
if (isNumericType(normalized) && column.getNumeric_precision() != null) {
|
if (isNumericType(normalized) && column.getNumeric_precision() != null) {
|
||||||
if (column.getNumeric_scale() != null) {
|
if (column.getNumeric_scale() != null) {
|
||||||
|
|||||||
@@ -565,6 +565,23 @@ class KingbaseAgentTest extends JdbcFakeExecutionBehaviorTest {
|
|||||||
Assertions.assertFalse(ddl.contains("unknown metadata"), ddl);
|
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
|
@Test
|
||||||
void regularListIndexesIncludesPrimaryUniqueAndSecondaryIndexes() {
|
void regularListIndexesIncludesPrimaryUniqueAndSecondaryIndexes() {
|
||||||
List<String> sql = new ArrayList<>();
|
List<String> sql = new ArrayList<>();
|
||||||
|
|||||||
Reference in new issue
Block a user