Skip to content

Commit 86c2a00

Browse files
gavinkingbeikov
authored andcommitted
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
1 parent 9c2c863 commit 86c2a00

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/ColumnDefinitions.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.type.descriptor.jdbc.JdbcType;
2121

2222
import java.util.List;
23+
import java.util.Locale;
2324

2425
import static org.hibernate.type.SqlTypes.isNumericOrDecimal;
2526
import static org.hibernate.type.SqlTypes.isStringType;
@@ -28,7 +29,7 @@ class ColumnDefinitions {
2829

2930
static boolean hasMatchingType(Column column, ColumnInformation columnInformation, Metadata metadata, Dialect dialect) {
3031
boolean typesMatch = dialect.equivalentTypes( column.getSqlTypeCode(metadata), columnInformation.getTypeCode() )
31-
|| stripArgs( getSqlType( column, metadata ) ).equalsIgnoreCase( columnInformation.getTypeName() );
32+
|| normalize( stripArgs( getSqlType( column, metadata ) ) ).equals( normalize( columnInformation.getTypeName() ) );
3233
if ( typesMatch ) {
3334
return true;
3435
}
@@ -239,8 +240,32 @@ private static boolean isPrimaryKeyIdentity(Table table, Metadata metadata, Dial
239240
);
240241
}
241242

242-
private static String stripArgs(String string) {
243-
int i = string.indexOf( '(' );
244-
return i > 0 ? string.substring( 0, i ).trim() : string;
243+
private static String normalize(String typeName) {
244+
if ( typeName == null ) {
245+
return null;
246+
}
247+
else {
248+
final String lowerCaseTypName = typeName.toLowerCase(Locale.ROOT);
249+
switch (lowerCaseTypName) {
250+
case "character":
251+
return "char";
252+
case "character varying":
253+
return "varchar";
254+
case "binary varying":
255+
return "varbinary";
256+
default:
257+
return lowerCaseTypName;
258+
}
259+
}
260+
}
261+
262+
private static String stripArgs(String typeExpression) {
263+
if ( typeExpression == null ) {
264+
return null;
265+
}
266+
else {
267+
int i = typeExpression.indexOf( '(' );
268+
return i > 0 ? typeExpression.substring( 0, i ).trim() : typeExpression;
269+
}
245270
}
246271
}

0 commit comments

Comments
 (0)