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 6592423b7d..30014fd7fe 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 @@ -24,9 +24,7 @@ object SchemaUtils { emptyMap() } else { tables.associateWith { t -> - t.columns.mapNotNull { c -> - c.referee?.let { it.table to c.columnType.nullable } - }.toMap() + t.foreignKeys.map { it.targetTable } } } } @@ -36,9 +34,7 @@ object SchemaUtils { fun parseTable(table: Table) { if (result.add(table)) { - table.columns.forEach { - it.referee?.table?.let(::parseTable) - } + table.foreignKeys.map { it.targetTable }.forEach(::parseTable) } } tables.forEach(::parseTable) @@ -54,7 +50,7 @@ object SchemaUtils { fun traverse(table: Table) { if (table !in visited) { visited += table - graph.getValue(table).forEach { (t, _) -> + graph.getValue(table).forEach { t -> if (t !in visited) { traverse(t) } @@ -79,7 +75,7 @@ object SchemaUtils { if (table in visited) return false recursion += table visited += table - return if (graph[table]!!.any { traverse(it.key) }) { + return if (graph[table]!!.any { traverse(it) }) { true } else { recursion -= table diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt index 7d3f7be669..e2d041fa0f 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt @@ -19,7 +19,7 @@ import org.jetbrains.exposed.sql.vendors.OracleDialect import org.jetbrains.exposed.sql.vendors.PrimaryKeyMetadata import org.junit.Test import java.math.BigDecimal -import java.util.* +import java.util.UUID import kotlin.properties.Delegates import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -540,7 +540,7 @@ class CreateMissingTablesAndColumnsTests : DatabaseTestsBase() { } @Test fun testCreateTableWithReferenceMultipleTimes() { - withTables(PlayerTable, SessionsTable) { + withTables(SessionsTable, PlayerTable) { SchemaUtils.createMissingTablesAndColumns(PlayerTable, SessionsTable) SchemaUtils.createMissingTablesAndColumns(PlayerTable, SessionsTable) } @@ -620,7 +620,7 @@ class CreateMissingTablesAndColumnsTests : DatabaseTestsBase() { @Test fun testCreateCompositePrimaryKeyTableAndCompositeForeignKeyTableMultipleTimes() { - withTables(CompositePrimaryKeyTable, CompositeForeignKeyTable) { + withTables(CompositeForeignKeyTable, CompositePrimaryKeyTable) { SchemaUtils.createMissingTablesAndColumns(CompositePrimaryKeyTable, CompositeForeignKeyTable) SchemaUtils.createMissingTablesAndColumns(CompositePrimaryKeyTable, CompositeForeignKeyTable) }