Skip to content

Commit

Permalink
Issue #934 (#934) (#936)
Browse files Browse the repository at this point in the history
Fix foreign key creation in PostgreSQL

Co-authored-by: freedom4live <novikov.aleksei.92@gmail.com>
Co-authored-by: Aleksei Novikov <aleksei.novikov@betpawa.com>
  • Loading branch information
3 people committed Jun 19, 2020
1 parent 56863e0 commit 1c4b1fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class JdbcDatabaseMetadataImpl(database: String, val metadata: DatabaseMetaData)
val fromTableName = getString("FKTABLE_NAME")!!
val fromColumnName = identifierManager.quoteIdentifierWhenWrongCaseOrNecessary(getString("FKCOLUMN_NAME")!!)
val fromColumn = allTables.getValue(fromTableName).columns.firstOrNull {
identifierManager.quoteIdentifierWhenWrongCaseOrNecessary(it.nameInDatabaseCase()) == fromColumnName
identifierManager.quoteIdentifierWhenWrongCaseOrNecessary(it.name) == fromColumnName
} ?: return@iterate null // Do not crash if there are missing fields in Exposed's tables
val constraintName = getString("FK_NAME")!!
val targetTableName = getString("PKTABLE_NAME")!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ class CreateMissingTablesAndColumnsTests : DatabaseTestsBase() {
}
}

@Test
fun testForeignKeyCreationInPostgres() {
val usersTable = object : IntIdTable("users") {}
val spacesTable = object : IntIdTable("spaces") {
val userId = reference("userId", usersTable)
}

withDb(TestDB.POSTGRESQL) {
SchemaUtils.createMissingTablesAndColumns(usersTable, spacesTable)
}
}

object MultipleIndexesTable: Table("H2_MULTIPLE_INDEXES") {
val value1 = varchar("value1", 255)
val value2 = varchar("value2", 255)
Expand Down

0 comments on commit 1c4b1fa

Please sign in to comment.