I'm having difficulty getting schema operations to...
# exposed
w
I'm having difficulty getting schema operations to work with a specified schema. I'm using postgres, I've already created a schema, but the createMissingTablesAndColumns fails with error "ERROR: no schema has been selected to create in". My attempt is below:
Copy code
fun generateSchema(config: Config) {
    val ds = PGSimpleDataSource()
    ds.serverNames = arrayOf(config.host)
    ds.databaseName = config.database
    ds.user = config.username
    ds.password = config.password
    ds.currentSchema = config.schema

    val actualDb = Database.connect(ds, databaseConfig = DatabaseConfig{
        defaultSchema = Schema(config.schema)
    })
    transaction(actualDb) {
        println(connection.schema)
        SchemaUtils.setSchema(Schema(config.schema))
        SchemaUtils.createMissingTablesAndColumns(*SCHEMA_LIST, withLogs = true)
    }
}
with logging enabled, the generated query is this:
CREATE TABLE IF NOT EXISTS users_d (id BIGSERIAL PRIMARY KEY, username VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, "password" VARCHAR(255) NOT NULL, salt VARCHAR(255) NULL, original_record BIGINT NULL, "updatedAt" TIMESTAMP NOT NULL, "updatedBy" BIGINT NULL)
Note, printing that connection.schema prints empty string.
After many hours of pulling out my hair, it turns out that error is also reported when the current user does not have create granted to him in that schema. Specifying the default schema was sufficient, the other uses on the data source and the setSchema call in the transation were unneccesary.