You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
object Headers : Table("headers") {
val id = uuid("id").primaryKey()
// tons more columns
}
object Transactions : Table("transactions") {
val headerId = (uuid("header_id").references(Headers.id)).index("custom_header_index")
// tons more columns
}
And I'm trying to create an index on the column with the foreign key. (To quickly query a relation)
But the createMissingTablesAndColumns function seems unwilling to do so probably because of the code bellow
for (table in tables) {
val existingTableIndices = currentDialect.existingIndices(table)[table].orEmpty().filterFKeys()
val mappedIndices = table.indices.filterFKeys()
existingTableIndices.forEach { index ->
mappedIndices.firstOrNull { it.onlyNameDiffer(index) }?.let {
exposedLogger.trace("Index on table '${table.tableName}' differs only in name: in db ${index.indexName} -> in mapping ${it.indexName}")
nameDiffers.add(index)
nameDiffers.add(it)
}
}
notMappedIndices.getOrPut(table.nameInDatabaseCase(), {hashSetOf()}).addAll(existingTableIndices.subtract(mappedIndices))
missingIndices.addAll(mappedIndices.subtract(existingTableIndices))
}
val mappedIndices = table.indices.filterFKeys() seems to filter out these indexes because it falsely assumes that they are foreign keys. Am I missing something or have I exposed an oversight?
The text was updated successfully, but these errors were encountered:
Did you try to switch an order in column definition from: (uuid("header_id").references(Headers.id)).index("custom_header_index")
to uuid("header_id").index("custom_header_index") references Headers.id
Here you declare what you want to create UUID column with name "header_id" and add an index "custom_header_index" to it.
I've got that output on H2:
CREATETABLEIF NOT EXISTS HEADERS (ID UUID PRIMARY KEY);
CREATETABLEIF NOT EXISTS TRANSACTIONS (HEADER_ID UUID NOT NULL, FOREIGN KEY (HEADER_ID) REFERENCES HEADERS(ID) ON DELETE RESTRICT ONUPDATE RESTRICT);
CREATEINDEXcustom_header_indexON TRANSACTIONS (HEADER_ID);
I just tested again with your example. On an empty database it works as expected. But if I create a database without indexes first and then add the indexes and run createMissingTablesAndColumns it doesn't work.
As I can see the bug was introduced in a 2015 when only MySQL and H2 were supported. And the problem was in the fact what MySQL automatically create an index for any foreign key.
…h `createMissingTablesAndColumns` / Partially reverted - we should distinguish Mysql's autocreated foreign key indexes from cases when real index wasn't created
I have a data structure like this
And I'm trying to create an index on the column with the foreign key. (To quickly query a relation)
But the
createMissingTablesAndColumns
function seems unwilling to do so probably because of the code bellowval mappedIndices = table.indices.filterFKeys()
seems to filter out these indexes because it falsely assumes that they are foreign keys. Am I missing something or have I exposed an oversight?The text was updated successfully, but these errors were encountered: