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
Hi.
I want to have capitalize table names in my postgresql database. Postgresql change names to lowercase unless they are quoted but with quoted table names in kotlin exposed 2 problems happen.
Constraint name generation goes wrong
When quoting my table name like:
object CustomerTable : IntIdTable("\"Customer\"")
constraints will be generated like below CONSTRAINT "fk_"Customer"_userId_id" FOREIGN KEY ("userId") REFERENCES "User"(id)
and database will complain about this constraint name.
Table existence check when generating table doesn't work
Constraint name problem can be by passed with giving name to all constraints yourself. But in SchemaUtils.createStatements method line
val toCreate = sortTablesByReferences(tables.toList()).filterNot { it.exists() }
won't work correctly. Because it.exists() is:
//
fun Table.exists(): Boolean = currentDialect.tableExists(this)
// Implementation in VendorDialect
override fun tableExists(table: Table): Boolean {
val tableScheme = table.tableName.substringBefore('.', "").takeIf { it.isNotEmpty() }
val scheme = tableScheme?.inProperCase() ?: TransactionManager.current().connection.metadata { currentScheme }
val allTables = getAllTableNamesCache().getValue(scheme)
return allTables.any {
when {
tableScheme != null -> it == table.nameInDatabaseCase()
scheme.isEmpty() -> it == table.nameInDatabaseCase()
else -> it == "$scheme.${table.tableNameWithoutScheme}".inProperCase()
}
}
}
now imagine having a table "User". in the else part 'it' value is "public.user" and result of "$scheme.${table.tableNameWithoutScheme}".inProperCase() is "public."user"". these 2 are not equal and result of it.exists() is always false. Then a single table comes for generation many times and database will complain about constraints that are generated before and already exist in database.
The text was updated successfully, but these errors were encountered:
Hi.
I want to have capitalize table names in my postgresql database. Postgresql change names to lowercase unless they are quoted but with quoted table names in kotlin exposed 2 problems happen.
When quoting my table name like:
constraints will be generated like below
CONSTRAINT "fk_"Customer"_userId_id" FOREIGN KEY ("userId") REFERENCES "User"(id)
and database will complain about this constraint name.
Constraint name problem can be by passed with giving name to all constraints yourself. But in
SchemaUtils.createStatements
method linewon't work correctly. Because
it.exists()
is:now imagine having a table "User". in the
else
part 'it' value is "public.user" and result of"$scheme.${table.tableNameWithoutScheme}".inProperCase()
is"public."user""
. these 2 are not equal and result ofit.exists()
is always false. Then a single table comes for generation many times and database will complain about constraints that are generated before and already exist in database.The text was updated successfully, but these errors were encountered: