Add support for multiple data source beans

Also implements the connection needed for the replay cache
This commit is contained in:
Stedoss 2024-11-02 20:37:28 +00:00
parent 81fd373f5c
commit e28d3e7211
3 changed files with 44 additions and 15 deletions

View File

@ -0,0 +1,22 @@
package com.nisemoe.nise.config
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.jdbc.DataSourceBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import org.springframework.transaction.annotation.EnableTransactionManagement
import javax.sql.DataSource
@Configuration
@EnableTransactionManagement
class DataSourceConfig {
@Primary
@Bean(name = ["niseDataSource"])
@ConfigurationProperties(prefix = "spring.datasource.nise")
fun niseDataSource(): DataSource = DataSourceBuilder.create().build()
@Bean(name = ["replayCacheDataSource"])
@ConfigurationProperties(prefix = "spring.datasource.replay-cache")
fun replayCacheDataSource(): DataSource = DataSourceBuilder.create().build()
}

View File

@ -1,14 +0,0 @@
spring.datasource.url=jdbc:postgresql://${POSTGRES_HOST:postgres}:${POSTGRES_PORT:5432}/${POSTGRES_DB:postgres}?currentSchema=public
spring.datasource.username=${POSTGRES_USER:postgres}
spring.datasource.password=${POSTGRES_PASS:postgres}
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.name=HikariPool-PostgreSQL
spring.flyway.enabled=${FLYWAY_ENABLED:true}
spring.flyway.schemas=public
# Batching
spring.datasource.hikari.data-source-properties.prepStmtCacheSize=250
spring.datasource.hikari.data-source-properties.prepStmtCacheSqlLimit=2048
spring.datasource.hikari.data-source-properties.useServerPrepStmts=true
spring.datasource.hikari.data-source-properties.rewriteBatchedStatements=true

View File

@ -33,3 +33,24 @@ spring.security.oauth2.client.provider.osu.authorization-uri=https://osu.ppy.sh/
spring.security.oauth2.client.provider.osu.token-uri=https://osu.ppy.sh/oauth/token spring.security.oauth2.client.provider.osu.token-uri=https://osu.ppy.sh/oauth/token
spring.security.oauth2.client.provider.osu.user-info-uri=https://osu.ppy.sh/api/v2/me/osu spring.security.oauth2.client.provider.osu.user-info-uri=https://osu.ppy.sh/api/v2/me/osu
spring.security.oauth2.client.provider.osu.user-name-attribute=username spring.security.oauth2.client.provider.osu.user-name-attribute=username
spring.datasource.nise.jdbcUrl=jdbc:postgresql://${POSTGRES_HOST:postgres}:${POSTGRES_PORT:5432}/${POSTGRES_DB:postgres}?currentSchema=public
spring.datasource.nise.username=${POSTGRES_USER:postgres}
spring.datasource.nise.password=${POSTGRES_PASS:postgres}
spring.datasource.nise.driver-class-name=org.postgresql.Driver
spring.datasource.nise.name=HikariPool-PostgreSQL
spring.datasource.replay-cache.jdbcUrl=jdbc:postgresql://${REPLAY_CACHE_HOST:postgres}:${REPLAY_CACHE_PORT:5433}/${REPLAY_CACHE_DB:REPLAY_CACHE}?currentSchema=public
spring.datasource.replay-cache.username=${REPLAY_CACHE_USER:postgres}
spring.datasource.replay-cache.password=${REPLAY_CACHE_PASS:postgres}
spring.datasource.replay-cache.driver-class-name=org.postgresql.Driver
spring.datasource.replay-cache.name=HikariPool-PostgreSQL
spring.flyway.enabled=${FLYWAY_ENABLED:true}
spring.flyway.schemas=public
# Batching
spring.datasource.hikari.data-source-properties.prepStmtCacheSize=250
spring.datasource.hikari.data-source-properties.prepStmtCacheSqlLimit=2048
spring.datasource.hikari.data-source-properties.useServerPrepStmts=true
spring.datasource.hikari.data-source-properties.rewriteBatchedStatements=true