}
boolean renamed = !oldTable.getName().equals(newTable.getName()) || !renamedColumns.isEmpty();
Map<String,String> preserveIndexes = new TreeMap<>();
TableName parentName = (newTable.getParentJoin() != null) ? newTable.getParentJoin().getParent().getName() : null;
state.descriptions.add(
new ChangedTableDescription(
oldTable.getTableId(),
oldTable.getName(),
newTable,
renamedColumns,
parentChange,
parentName,
EMPTY_STRING_MAP,
preserveIndexes,
droppedSequences,
addedIdentity,
addedIndexes,
finalChangeLevel == ChangeLevel.TABLE,
isParentChanged() || primaryKeyChanged
)
);
if(!isParentChanged() && !primaryKeyChanged) {
for(Index index : newTable.getIndexesIncludingInternal()) {
String oldName = index.getIndexName().getName();
String newName = findNewName(state.tableIndexChanges, oldName);
if(!containsOldOrNew(state.tableIndexChanges, oldName)) {
preserveIndexes.put(oldName, newName);
}
}
}
Collection<Join> oldChildJoins = new ArrayList<>(oldTable.getCandidateChildJoins());
for(Join join : oldChildJoins) {
Table oldChildTable = join.getChild();
// If referenced column has anymore has a TABLE change (or is missing), join needs dropped
boolean dropParent = false;
for(JoinColumn joinCol : join.getJoinColumns()) {
Column oldColumn = joinCol.getParent().getColumn();
String newName = findNewName(state.columnChanges, oldColumn.getName());
if(newName == null) {
dropParent = true;
} else {
Column newColumn = newTable.getColumn(newName);
if(compare(oldColumn, newColumn) == ChangeLevel.TABLE) {
dropParent = true;
}
}
}
boolean preserve = false;
ParentChange change = null;
// If PK changed and table had children, PK was dropped
if(primaryKeyChanged || dropParent) {
updateFinalChangeLevel(ChangeLevel.GROUP);
change = ParentChange.DROP;
} else if(isParentChanged() || (parentChange == ParentChange.ADD)) {
updateFinalChangeLevel(ChangeLevel.GROUP);
change = ParentChange.UPDATE;
} else if(renamed) {
updateFinalChangeLevel(ChangeLevel.METADATA);
change = ParentChange.META;
preserve = true;
}
if(change != null) {
TableName newParent = (change == ParentChange.DROP) ? null : newTable.getName();
trackChangedTable(oldChildTable, change, newParent, renamedColumns, preserve);
propagateChildChange(oldChildTable, ParentChange.UPDATE, preserve);
}
}