https://kotlinlang.org logo
#exposed
Title
# exposed
l

Luca Sas

04/27/2021, 6:48 PM
Hi, I am on ktor 1.5.2 and I am having issues with SchemaUtils.create. I have 3 tables, and the third has a reference to the first one. When it gets to creating the third table it concludes that the first one doesnt exist and tries to create it again which causes an error "relation "users_username_unique" already exists". I debugged and stepped thru the code and found that the problem is in VendorDialect.tableExists function.
Copy code
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()
            }
        }
    }
What happens here by looking at the debugger is that
alltables
is
[ "public.tablename", "public.someothertablename" ]
but
table.name
misses the schema name and I am not sure why. The code is fairly straightforward and I used
SchemaUtils.create
successfully in the past.
t

tapac

04/28/2021, 7:24 PM
Can you share a sample project on github to test?