Skip to content

HHH-19614 Apply column check constraints as table constraints if possible #10571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,41 @@ protected void applyTableTypeString(StringBuilder buf) {

protected void applyTableCheck(Table table, StringBuilder buf) {
if ( dialect.supportsTableCheck() ) {
if ( !dialect.supportsColumnCheck() ) {
for ( Column column : table.getColumns() ) {
// some databases (Maria, SQL Server) don't like multiple 'check' clauses
final List<CheckConstraint> checkConstraints = column.getCheckConstraints();
long anonConstraints = checkConstraints.stream().filter( CheckConstraint::isAnonymous ).count();
if ( anonConstraints == 1 ) {
for ( CheckConstraint constraint : checkConstraints ) {
buf.append( "," ).append( constraint.constraintString( dialect ) );
}
}
else {
boolean first = true;
for ( CheckConstraint constraint : checkConstraints ) {
if ( constraint.isAnonymous() ) {
if ( first ) {
buf.append( "," ).append( " check (" );
first = false;
}
else {
buf.append( " and " );
}
buf.append( constraint.getConstraintInParens() );
}
}
if ( !first ) {
buf.append( ")" );
}
for ( CheckConstraint constraint : checkConstraints ) {
if ( constraint.isNamed() ) {
buf.append( constraint.constraintString( dialect ) );
}
}
}
}
}
for ( CheckConstraint constraint : table.getChecks() ) {
buf.append( "," ).append( constraint.constraintString( dialect ) );
}
Expand Down
Loading