fun initPostgres()

in src/main/kotlin/org/jetbrains/slackUnfurls/storage/postgres/Interface.kt [534:554]


fun initPostgres(): PostgresStorage? {
    val postgresUrl = config.tryGetString("storage.postgres.url")?.let { Url(it) } ?: return null

    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(*allTables.toTypedArray())
    }

    return PostgresStorage(connection)
}