fun initDbConnection()

in kotlin/app-homepage-react/src/main/kotlin/org/homepage/db/DbInit.kt [10:29]


fun initDbConnection() {
    val postgresUrl = config.tryGetString("storage.postgres.url")?.let { Url(it) }
        ?: throw IllegalArgumentException("storage.postgres.url configuration parameter not set or invalid")

    val connection = Database.connect(
        url = URLBuilder(postgresUrl).apply {
            protocol = URLProtocol("jdbc:postgresql", 5432)
            port = postgresUrl.port
            user = null
            password = null
        }.buildString(),
        driver = "org.postgresql.Driver",
        user = postgresUrl.user!!,
        password = postgresUrl.password!!
    )

    transaction(connection) {
        SchemaUtils.createMissingTablesAndColumns(AppInstallation)
    }
}