diff --git a/commercedbsync/src/com/sap/cx/boosters/commercedbsync/processors/impl/IndexAlignerPostProcessor.java b/commercedbsync/src/com/sap/cx/boosters/commercedbsync/processors/impl/IndexAlignerPostProcessor.java index 408b2ed..cb69a39 100644 --- a/commercedbsync/src/com/sap/cx/boosters/commercedbsync/processors/impl/IndexAlignerPostProcessor.java +++ b/commercedbsync/src/com/sap/cx/boosters/commercedbsync/processors/impl/IndexAlignerPostProcessor.java @@ -37,7 +37,7 @@ public void process(final CopyContext context) final DataRepository dataTargetRepository = migrationContext.getDataTargetRepository(); final String indiciesSQL = generateAlterTablesSql(migrationContext); indiciesSQL.lines().forEach(indexSQL -> { - if(StringUtils.isNotBlank(indexSQL)) + if (StringUtils.isNotBlank(indexSQL)) { LOG.info("Executing {}", indexSQL); try @@ -56,37 +56,47 @@ public void process(final CopyContext context) private String generateAlterTablesSql(final MigrationContext migrationContext) { - final Database sourceDatabase = migrationContext.getDataSourceRepository().asDatabase(); - final DataRepository dataTargetRepository = migrationContext.getDataTargetRepository(); - final Database targetDatabase = dataTargetRepository.asDatabase(); - final Set excludedIndices = getExcludedIndicies(); - - for (final String copiedTable : migrationContext.getIncludedTables()) + String alterTablesSql = ""; + try { - final Table sourceTable = sourceDatabase.findTable(copiedTable); - final Table targetTable = targetDatabase.findTable(copiedTable); - if (sourceTable != null && targetTable != null) + final Database sourceDatabase = migrationContext.getDataSourceRepository().asDatabase(); + final DataRepository dataTargetRepository = migrationContext.getDataTargetRepository(); + final Database targetDatabase = dataTargetRepository.asDatabase(); + final Set excludedIndices = getExcludedIndicies(); + + for (final String copiedTable : migrationContext.getIncludedTables()) { - final Index[] sourceTableIndices = sourceTable.getIndices(); - final Index[] targetTableIndices = targetTable.getIndices(); - for (final Index sourceTableIndex : sourceTableIndices) + final Table sourceTable = sourceDatabase.findTable(copiedTable); + final Table targetTable = targetDatabase.findTable(copiedTable); + if (sourceTable != null && targetTable != null) { - if (!ArrayUtils.contains(targetTableIndices, sourceTableIndex) - && !excludedIndices.contains((sourceTable.getName() + "." + sourceTableIndex.getName()).toLowerCase())) + final Index[] sourceTableIndices = sourceTable.getIndices(); + final Index[] targetTableIndices = targetTable.getIndices(); + for (final Index sourceTableIndex : sourceTableIndices) { - LOG.debug("Found missing index {} for {}", sourceTableIndex, copiedTable); - targetTable.addIndex(sourceTableIndex); + if (!ArrayUtils.contains(targetTableIndices, sourceTableIndex) + && !excludedIndices.contains((sourceTable.getName() + "." + sourceTableIndex.getName()).toLowerCase())) + { + LOG.debug("Found missing index {} for {}", sourceTableIndex, copiedTable); + targetTable.addIndex(sourceTableIndex); + } } } + else + { + LOG.warn("Table {} is not found one of the databases: source[{}], target[{}]", copiedTable, sourceTable, + targetTable); + } } - else - { - LOG.warn("Table {} is not found one of the databases: source[{}], target[{}]", copiedTable, sourceTable, targetTable); - } + + alterTablesSql = dataTargetRepository.asPlatform().getAlterTablesSql(targetDatabase); + LOG.debug("Generated alter table sql for missing indexes: {}", alterTablesSql); + } + catch (final Exception e) + { + LOG.error("Alter table generation failed", e); } - final String alterTablesSql = dataTargetRepository.asPlatform().getAlterTablesSql(targetDatabase); - LOG.debug("Generated alter table sql for missing indexes: {}", alterTablesSql); return alterTablesSql; } diff --git a/docs/configuration/CONFIGURATION-GUIDE.md b/docs/configuration/CONFIGURATION-GUIDE.md index 6d62224..c9b7f75 100644 --- a/docs/configuration/CONFIGURATION-GUIDE.md +++ b/docs/configuration/CONFIGURATION-GUIDE.md @@ -74,8 +74,9 @@ For example with media filtered just for the images folder is possible to achiev migration.data.view.t.medias.enabled=true # enable view generation # If you are joining more than one tables in the where clause then use a columnPrefix label migration.data.view.t.medias.columnPrefix=item_t1 -# name `v_medias` is generated due to default name pattern value v_%s. No need to configure -migration.data.view.t.medias.joinWhereClause=FROM medias item_t1 JOIN mediafolders item_t2 ON item_t1.p_folder = item_t2.PK WHERE (item_t2.p_qualifier like 'images') +# The joinWhereClause is used within view definition. i.e. CREATE VIEW v_media AS SELECT * FROM {joinWhereClause} +# name `v_medias` is generated due to default name pattern value v_%s as the view name so no need to configure it for joinWhereClause +migration.data.view.t.medias.joinWhereClause=medias item_t1 JOIN mediafolders item_t2 ON item_t1.p_folder = item_t2.PK WHERE (item_t2.p_qualifier like 'images') ``` Output for that will be like this: