HHH-10066 - Drop and recreate AuxiliaryDatabaseObjects as part of schema update
(cherry picked from commit 59a8d3122f
)
This commit is contained in:
parent
398cec2bcc
commit
4899a1db96
|
@ -13,6 +13,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
|
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||||
import org.hibernate.boot.model.relational.Database;
|
import org.hibernate.boot.model.relational.Database;
|
||||||
import org.hibernate.boot.model.relational.Exportable;
|
import org.hibernate.boot.model.relational.Exportable;
|
||||||
import org.hibernate.boot.model.relational.Namespace;
|
import org.hibernate.boot.model.relational.Namespace;
|
||||||
|
@ -72,6 +73,38 @@ public class SchemaMigratorImpl implements SchemaMigrator {
|
||||||
final Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
final Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
||||||
|
|
||||||
final Database database = metadata.getDatabase();
|
final Database database = metadata.getDatabase();
|
||||||
|
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
|
||||||
|
final Dialect dialect = jdbcEnvironment.getDialect();
|
||||||
|
|
||||||
|
// Drop all AuxiliaryDatabaseObjects
|
||||||
|
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
|
||||||
|
if ( !auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
applySqlStrings(
|
||||||
|
dialect.getAuxiliaryDatabaseObjectExporter().getSqlDropStrings( auxiliaryDatabaseObject, metadata ),
|
||||||
|
targets,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create before-table AuxiliaryDatabaseObjects
|
||||||
|
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
|
||||||
|
if ( auxiliaryDatabaseObject.beforeTablesOnCreation() ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( !auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
applySqlStrings(
|
||||||
|
auxiliaryDatabaseObject.sqlCreateStrings( jdbcEnvironment.getDialect() ),
|
||||||
|
targets,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
boolean tryToCreateCatalogs = false;
|
boolean tryToCreateCatalogs = false;
|
||||||
boolean tryToCreateSchemas = false;
|
boolean tryToCreateSchemas = false;
|
||||||
|
|
||||||
|
@ -175,6 +208,22 @@ public class SchemaMigratorImpl implements SchemaMigrator {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create after-table AuxiliaryDatabaseObjects
|
||||||
|
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
|
||||||
|
if ( !auxiliaryDatabaseObject.beforeTablesOnCreation() ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( !auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
applySqlStrings(
|
||||||
|
auxiliaryDatabaseObject.sqlCreateStrings( jdbcEnvironment.getDialect() ),
|
||||||
|
targets,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTable(Table table, Metadata metadata, List<Target> targets) {
|
private void createTable(Table table, Metadata metadata, List<Target> targets) {
|
||||||
|
|
Loading…
Reference in New Issue