Skip to content

Commit

Permalink
Merge pull request #3 from hakan-agdere-sap/feature/additional-update…
Browse files Browse the repository at this point in the history
…s-1-1

Documentation update and a bugfix
  • Loading branch information
ashwinineha authored Feb 13, 2023
2 parents 48c3d68 + 9a09d2e commit 6f6244d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> 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<String> 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;
}

Expand Down
5 changes: 3 additions & 2 deletions docs/configuration/CONFIGURATION-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6f6244d

Please sign in to comment.