Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #934 (https://github.com/JetBrains/Exposed/issues/934) #936

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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