HHH-16177 Take into account the default catalog/schema when creating/dropping catalogs/schemas
This commit is contained in:
parent
7be545574a
commit
82b89e2a22
|
@ -535,14 +535,18 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
|||
Formatter formatter,
|
||||
boolean tryToCreateCatalogs,
|
||||
boolean tryToCreateSchemas,
|
||||
Set<Identifier> exportedCatalogs, Namespace namespace, GenerationTarget[] targets) {
|
||||
Set<Identifier> exportedCatalogs, Namespace namespace,
|
||||
SqlStringGenerationContext context,
|
||||
GenerationTarget[] targets) {
|
||||
if ( tryToCreateCatalogs || tryToCreateSchemas ) {
|
||||
if ( tryToCreateCatalogs ) {
|
||||
final Identifier catalogLogicalName = namespace.getName().getCatalog();
|
||||
final Identifier catalogPhysicalName = namespace.getPhysicalName().getCatalog();
|
||||
Namespace.Name logicalName = namespace.getName();
|
||||
Namespace.Name physicalName = namespace.getPhysicalName();
|
||||
|
||||
if ( tryToCreateCatalogs ) {
|
||||
final Identifier catalogLogicalName = logicalName.getCatalog();
|
||||
final Identifier catalogPhysicalName = context.catalogWithDefault( physicalName.getCatalog() );
|
||||
if ( catalogPhysicalName != null && !exportedCatalogs.contains( catalogLogicalName )
|
||||
&& !existingDatabase.catalogExists( catalogLogicalName ) ) {
|
||||
&& !existingDatabase.catalogExists( catalogPhysicalName ) ) {
|
||||
applySqlStrings(
|
||||
false,
|
||||
dialect.getCreateCatalogCommand( catalogPhysicalName.render( dialect ) ),
|
||||
|
@ -554,16 +558,17 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
|||
}
|
||||
}
|
||||
|
||||
if ( tryToCreateSchemas
|
||||
&& namespace.getPhysicalName().getSchema() != null
|
||||
&& !existingDatabase.schemaExists( namespace.getName() ) ) {
|
||||
applySqlStrings(
|
||||
false,
|
||||
dialect.getCreateSchemaCommand( namespace.getPhysicalName().getSchema().render( dialect ) ),
|
||||
formatter,
|
||||
options,
|
||||
targets
|
||||
);
|
||||
if ( tryToCreateSchemas ) {
|
||||
final Identifier schemaPhysicalName = context.schemaWithDefault( physicalName.getSchema() );
|
||||
if ( schemaPhysicalName != null && !existingDatabase.schemaExists( physicalName ) ) {
|
||||
applySqlStrings(
|
||||
false,
|
||||
dialect.getCreateSchemaCommand( schemaPhysicalName.render( dialect ) ),
|
||||
formatter,
|
||||
options,
|
||||
targets
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator {
|
|||
tryToCreateSchemas,
|
||||
exportedCatalogs,
|
||||
namespace,
|
||||
sqlStringGenerationContext,
|
||||
targets
|
||||
);
|
||||
final NameSpaceTablesInformation tables = existingDatabase.getTablesInformation( namespace );
|
||||
|
|
|
@ -63,6 +63,7 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator {
|
|||
tryToCreateSchemas,
|
||||
exportedCatalogs,
|
||||
namespace,
|
||||
sqlStringGenerationContext,
|
||||
targets
|
||||
);
|
||||
for ( Table table : namespace.getTables() ) {
|
||||
|
|
|
@ -233,11 +233,12 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ( tryToCreateCatalogs ) {
|
||||
final Identifier catalogLogicalName = namespace.getName().getCatalog();
|
||||
final Identifier catalogPhysicalName =
|
||||
sqlStringGenerationContext.catalogWithDefault( namespace.getPhysicalName().getCatalog() );
|
||||
Namespace.Name logicalName = namespace.getName();
|
||||
Namespace.Name physicalName = namespace.getPhysicalName();
|
||||
|
||||
if ( tryToCreateCatalogs ) {
|
||||
final Identifier catalogLogicalName = logicalName.getCatalog();
|
||||
final Identifier catalogPhysicalName = sqlStringGenerationContext.catalogWithDefault( physicalName.getCatalog() );
|
||||
if ( catalogPhysicalName != null && !exportedCatalogs.contains( catalogLogicalName ) ) {
|
||||
applySqlStrings(
|
||||
dialect.getCreateCatalogCommand( catalogPhysicalName.render( dialect ) ),
|
||||
|
@ -249,15 +250,16 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
|||
}
|
||||
}
|
||||
|
||||
final Identifier schemaPhysicalName =
|
||||
sqlStringGenerationContext.schemaWithDefault( namespace.getPhysicalName().getSchema() );
|
||||
if ( tryToCreateSchemas && schemaPhysicalName != null ) {
|
||||
applySqlStrings(
|
||||
dialect.getCreateSchemaCommand( schemaPhysicalName.render( dialect ) ),
|
||||
formatter,
|
||||
options,
|
||||
targets
|
||||
);
|
||||
if ( tryToCreateSchemas ) {
|
||||
final Identifier schemaPhysicalName = sqlStringGenerationContext.schemaWithDefault( physicalName.getSchema() );
|
||||
if ( schemaPhysicalName != null ) {
|
||||
applySqlStrings(
|
||||
dialect.getCreateSchemaCommand( schemaPhysicalName.render( dialect ) ),
|
||||
formatter,
|
||||
options,
|
||||
targets
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,29 +275,34 @@ public class SchemaDropperImpl implements SchemaDropper {
|
|||
);
|
||||
}
|
||||
|
||||
if ( tryToDropCatalogs || tryToDropSchemas ) {
|
||||
Set<Identifier> exportedCatalogs = new HashSet<Identifier>();
|
||||
|
||||
for ( Namespace namespace : database.getNamespaces() ) {
|
||||
if ( tryToDropCatalogs || tryToDropSchemas) {
|
||||
final Set<Identifier> exportedCatalogs = new HashSet<Identifier>();
|
||||
|
||||
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
|
||||
if ( !schemaFilter.includeNamespace( namespace ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( tryToDropSchemas && namespace.getPhysicalName().getSchema() != null ) {
|
||||
applySqlStrings(
|
||||
dialect.getDropSchemaCommand(
|
||||
namespace.getPhysicalName().getSchema().render( dialect )
|
||||
),
|
||||
formatter,
|
||||
options,
|
||||
targets
|
||||
);
|
||||
}
|
||||
if ( tryToDropCatalogs ) {
|
||||
final Identifier catalogLogicalName = namespace.getName().getCatalog();
|
||||
final Identifier catalogPhysicalName = namespace.getPhysicalName().getCatalog();
|
||||
Namespace.Name logicalName = namespace.getName();
|
||||
Namespace.Name physicalName = namespace.getPhysicalName();
|
||||
|
||||
if ( tryToDropSchemas ) {
|
||||
final Identifier schemaPhysicalName = sqlStringGenerationContext.schemaWithDefault( physicalName.getSchema() );
|
||||
if ( schemaPhysicalName != null ) {
|
||||
applySqlStrings(
|
||||
dialect.getDropSchemaCommand(
|
||||
schemaPhysicalName.render( dialect )
|
||||
),
|
||||
formatter,
|
||||
options,
|
||||
targets
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (tryToDropCatalogs) {
|
||||
final Identifier catalogLogicalName = logicalName.getCatalog();
|
||||
final Identifier catalogPhysicalName = sqlStringGenerationContext.catalogWithDefault( physicalName.getCatalog() );
|
||||
if ( catalogPhysicalName != null && !exportedCatalogs.contains( catalogLogicalName ) ) {
|
||||
applySqlStrings(
|
||||
dialect.getDropCatalogCommand(
|
||||
|
|
Loading…
Reference in New Issue