Skip to content

Commit

Permalink
Merge pull request #1476 from thehyve/always-create-index
Browse files Browse the repository at this point in the history
Always try create new index
  • Loading branch information
frankyhollywood authored Jan 29, 2024
2 parents 5fb4da6 + 2ea6724 commit 51ac573
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ void createOrUpdateJoinTable(Table table) throws SQLException {
log.debug("Check if table {} exists ...", table.name);
var resultSet = connection.getMetaData().getTables(null, null, table.name, null);
var tableExists = resultSet.next();

if (!tableExists) {
createTable(table, connection);
createIndexes(table, connection);
createIndexesIfNotExist(table, connection);
} else {
updateTable(table, connection);
createIndexesIfNotExist(table, connection);
}
}
}
Expand Down Expand Up @@ -169,8 +170,8 @@ private void createTable(Table table, Connection connection) throws SQLException
log.info("Table {} created.", table.name);
}

private void createIndexes(Table table, Connection connection) throws SQLException {
private void createIndexesIfNotExist(Table table, Connection connection) throws SQLException {

var keys = table.columns.stream()
.filter(column -> column.type == ColumnType.Identifier)
.map(column -> column.name)
Expand All @@ -186,7 +187,7 @@ private void createIndexes(Table table, Connection connection) throws SQLExcepti
connection.createStatement().execute(command);
log.info("Index {} created.", indexName);
}

connection.setAutoCommit(false);
}

Expand Down

0 comments on commit 51ac573

Please sign in to comment.