HHH-18296 call set client_min_messages = WARNING before dropping tables on Postgres

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-06-26 13:20:26 +02:00 committed by Yoann Rodière
parent ea468e774b
commit ad55fd0010
3 changed files with 25 additions and 0 deletions

View File

@ -2373,6 +2373,15 @@ public abstract class Dialect implements ConversionContext, TypeContributor, Fun
return false; return false;
} }
/**
* A command to execute before dropping tables.
*
* @return A SQL statement, or {@code null}
*/
public String getBeforeDropStatement() {
return null;
}
/** /**
* The command used to drop a table with the given name, usually * The command used to drop a table with the given name, usually
* {@code drop table tab_name}. * {@code drop table tab_name}.
@ -2380,7 +2389,12 @@ public abstract class Dialect implements ConversionContext, TypeContributor, Fun
* @param tableName The name of the table to drop * @param tableName The name of the table to drop
* *
* @return The {@code drop table} statement as a string * @return The {@code drop table} statement as a string
*
* @deprecated No longer used
*
* @see StandardTableExporter#getSqlDropStrings
*/ */
@Deprecated(since = "6.6")
public String getDropTableString(String tableName) { public String getDropTableString(String tableName) {
final StringBuilder buf = new StringBuilder( "drop table " ); final StringBuilder buf = new StringBuilder( "drop table " );
if ( supportsIfExistsBeforeTableName() ) { if ( supportsIfExistsBeforeTableName() ) {

View File

@ -783,6 +783,14 @@ public class PostgreSQLDialect extends Dialect {
return true; return true;
} }
@Override
public String getBeforeDropStatement() {
// by default, the Postgres driver reports
// NOTICE: table "nonexistent" does not exist, skipping
// as a JDBC SQLWarning
return "set client_min_messages = WARNING";
}
@Override @Override
public String getAlterColumnTypeString(String columnName, String columnType, String columnDefinition) { public String getAlterColumnTypeString(String columnName, String columnType, String columnDefinition) {
// would need multiple statements to 'set not null'/'drop not null', 'set default'/'drop default', 'set generated', etc // would need multiple statements to 'set not null'/'drop not null', 'set default'/'drop default', 'set generated', etc

View File

@ -63,6 +63,7 @@ import org.jboss.logging.Logger;
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize; import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
import static org.hibernate.tool.schema.internal.Helper.applyScript; import static org.hibernate.tool.schema.internal.Helper.applyScript;
import static org.hibernate.tool.schema.internal.Helper.applySqlString;
import static org.hibernate.tool.schema.internal.Helper.applySqlStrings; import static org.hibernate.tool.schema.internal.Helper.applySqlStrings;
import static org.hibernate.tool.schema.internal.Helper.createSqlStringGenerationContext; import static org.hibernate.tool.schema.internal.Helper.createSqlStringGenerationContext;
import static org.hibernate.tool.schema.internal.Helper.interpretFormattingEnabled; import static org.hibernate.tool.schema.internal.Helper.interpretFormattingEnabled;
@ -209,6 +210,8 @@ public class SchemaDropperImpl implements SchemaDropper {
// NOTE : init commands are irrelevant for dropping... // NOTE : init commands are irrelevant for dropping...
applySqlString( dialect.getBeforeDropStatement(), formatter, options, targets );
final SqlStringGenerationContext context = createSqlStringGenerationContext( options, metadata ); final SqlStringGenerationContext context = createSqlStringGenerationContext( options, metadata );
// Reverse the list on drop to retain possible dependencies // Reverse the list on drop to retain possible dependencies
dropAuxiliaryObjectsBeforeTables( metadata, options, dialect, formatter, context, targets ); dropAuxiliaryObjectsBeforeTables( metadata, options, dialect, formatter, context, targets );