HHH-17233 be a little more forgiving when comparing column types in schema validation
this "fix" is not really strictly-speaking necessary, but it does reduce false positives in a very tiny number of cases
This commit is contained in:
parent
9c2c863f80
commit
86c2a0062d
|
@ -20,6 +20,7 @@ import org.hibernate.tool.schema.extract.spi.ColumnInformation;
|
||||||
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.hibernate.type.SqlTypes.isNumericOrDecimal;
|
import static org.hibernate.type.SqlTypes.isNumericOrDecimal;
|
||||||
import static org.hibernate.type.SqlTypes.isStringType;
|
import static org.hibernate.type.SqlTypes.isStringType;
|
||||||
|
@ -28,7 +29,7 @@ class ColumnDefinitions {
|
||||||
|
|
||||||
static boolean hasMatchingType(Column column, ColumnInformation columnInformation, Metadata metadata, Dialect dialect) {
|
static boolean hasMatchingType(Column column, ColumnInformation columnInformation, Metadata metadata, Dialect dialect) {
|
||||||
boolean typesMatch = dialect.equivalentTypes( column.getSqlTypeCode(metadata), columnInformation.getTypeCode() )
|
boolean typesMatch = dialect.equivalentTypes( column.getSqlTypeCode(metadata), columnInformation.getTypeCode() )
|
||||||
|| stripArgs( getSqlType( column, metadata ) ).equalsIgnoreCase( columnInformation.getTypeName() );
|
|| normalize( stripArgs( getSqlType( column, metadata ) ) ).equals( normalize( columnInformation.getTypeName() ) );
|
||||||
if ( typesMatch ) {
|
if ( typesMatch ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -239,8 +240,32 @@ class ColumnDefinitions {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String stripArgs(String string) {
|
private static String normalize(String typeName) {
|
||||||
int i = string.indexOf( '(' );
|
if ( typeName == null ) {
|
||||||
return i > 0 ? string.substring( 0, i ).trim() : string;
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final String lowerCaseTypName = typeName.toLowerCase(Locale.ROOT);
|
||||||
|
switch (lowerCaseTypName) {
|
||||||
|
case "character":
|
||||||
|
return "char";
|
||||||
|
case "character varying":
|
||||||
|
return "varchar";
|
||||||
|
case "binary varying":
|
||||||
|
return "varbinary";
|
||||||
|
default:
|
||||||
|
return lowerCaseTypName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String stripArgs(String typeExpression) {
|
||||||
|
if ( typeExpression == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int i = typeExpression.indexOf( '(' );
|
||||||
|
return i > 0 ? typeExpression.substring( 0, i ).trim() : typeExpression;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue