From 118a196ad0359a4a940242d4012fd285f5477606 Mon Sep 17 00:00:00 2001 From: Jocelyne Date: Wed, 24 Jan 2024 14:26:18 +0100 Subject: [PATCH] -rearrange logic in checkExcessiveIndices -rearrange logic in checkExcessiveForeignKeyConstraints --- .../org/jetbrains/exposed/sql/SchemaUtils.kt | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt index 26f78947d7..87886eb88e 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt @@ -538,14 +538,17 @@ object SchemaUtils { */ @Suppress("NestedBlockDepth") fun checkExcessiveIndices(vararg tables: Table, withLogs: Boolean): List { - val toDrop = HashSet() - val excessiveIndices = currentDialect.existingIndices(*tables).flatMap { (_, indices) -> indices }.groupBy { index -> Triple(index.table, index.unique, index.columns.joinToString { column -> column.name }) } .filter { (_, indices) -> indices.size > 1 } - if (excessiveIndices.isNotEmpty()) { + + return if (excessiveIndices.isEmpty()) { + emptyList() + } else { + val toDrop = HashSet() + if (withLogs) { exposedLogger.warn("List of excessive indices:") excessiveIndices.forEach { (triple, indices) -> @@ -565,9 +568,9 @@ object SchemaUtils { } } } - } - return toDrop.toList() + toDrop.toList() + } } /** @@ -578,10 +581,13 @@ object SchemaUtils { */ @Suppress("NestedBlockDepth") fun checkExcessiveForeignKeyConstraints(vararg tables: Table, withLogs: Boolean): List { - val toDrop = HashSet() - val excessiveConstraints = currentDialect.columnConstraints(*tables).filter { (_, fkConstraints) -> fkConstraints.size > 1 } - if (excessiveConstraints.isNotEmpty()) { + + return if (excessiveConstraints.isEmpty()) { + emptyList() + } else { + val toDrop = HashSet() + if (withLogs) { exposedLogger.warn("List of excessive foreign key constraints:") excessiveConstraints.forEach { (table, columns), fkConstraints -> @@ -604,9 +610,9 @@ object SchemaUtils { } } } - } - return toDrop.toList() + toDrop.toList() + } } /** Returns list of indices missed in database **/