mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Allow using legacy database connections (#1785)
* Allow using legacy db connections * Lint * Description and docs
This commit is contained in:
@@ -245,11 +245,13 @@ server.databaseType = H2 # H2, POSTGRESQL
|
|||||||
server.databaseUrl = "postgresql://localhost:5432/suwayomi"
|
server.databaseUrl = "postgresql://localhost:5432/suwayomi"
|
||||||
server.databaseUsername = ""
|
server.databaseUsername = ""
|
||||||
server.databasePassword = ""
|
server.databasePassword = ""
|
||||||
|
server.useHikariConnectionPool = true
|
||||||
```
|
```
|
||||||
- `server.databaseType` chooses which type of database to use. [H2](https://en.wikipedia.org/wiki/H2_Database_Engine) is the default; it is a simple file-based database for Java applications. Since it is only based on files without a server process, file corruption can be common when the server is not shut down properly. [PostgreSQL](https://en.wikipedia.org/wiki/PostgreSQL) is a popular cross-platform, stable database. To use PostgreSQL, you need to run an instance yourself.
|
- `server.databaseType` chooses which type of database to use. [H2](https://en.wikipedia.org/wiki/H2_Database_Engine) is the default; it is a simple file-based database for Java applications. Since it is only based on files without a server process, file corruption can be common when the server is not shut down properly. [PostgreSQL](https://en.wikipedia.org/wiki/PostgreSQL) is a popular cross-platform, stable database. To use PostgreSQL, you need to run an instance yourself.
|
||||||
- `server.databaseUrl` the URL where to find the PostgreSQL server, including the database name.
|
- `server.databaseUrl` the URL where to find the PostgreSQL server, including the database name.
|
||||||
- `server.databaseUsername` the username with which to authenticate at the PostgreSQL instance.
|
- `server.databaseUsername` the username with which to authenticate at the PostgreSQL instance.
|
||||||
- `server.databasePassword` the username with which to authenticate at the PostgreSQL instance.
|
- `server.databasePassword` the username with which to authenticate at the PostgreSQL instance.
|
||||||
|
- `server.useHikariConnectionPool` use Hikari Connection Pool to connect to the database.
|
||||||
|
|
||||||
**Note:** The example [docker-compose.yml file](https://github.com/Suwayomi/Suwayomi-Server-docker/blob/main/docker-compose.yml) contains everything you need to get started with Suwayomi+PostgreSQL. Please be aware that PostgreSQL support is currently still in beta.
|
**Note:** The example [docker-compose.yml file](https://github.com/Suwayomi/Suwayomi-Server-docker/blob/main/docker-compose.yml) contains everything you need to get started with Suwayomi+PostgreSQL. Please be aware that PostgreSQL support is currently still in beta.
|
||||||
|
|
||||||
|
|||||||
@@ -914,6 +914,14 @@ class ServerConfig(
|
|||||||
key = "serveConversions"
|
key = "serveConversions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val useHikariConnectionPool: MutableStateFlow<Boolean> by BooleanSetting(
|
||||||
|
protoNumber = 85,
|
||||||
|
group = SettingGroup.DATABASE,
|
||||||
|
defaultValue = true,
|
||||||
|
excludeFromBackup = true,
|
||||||
|
description = "Use Hikari Connection Pool to connect to the database.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** ****************************************************************** **/
|
/** ****************************************************************** **/
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ data class DatabaseSettings(
|
|||||||
val databaseUrl: String,
|
val databaseUrl: String,
|
||||||
val databaseUsername: String,
|
val databaseUsername: String,
|
||||||
val databasePassword: String,
|
val databasePassword: String,
|
||||||
|
val useHikariConnectionPool: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
val androidCompat by lazy { AndroidCompat() }
|
val androidCompat by lazy { AndroidCompat() }
|
||||||
@@ -398,17 +399,19 @@ fun applicationSetup() {
|
|||||||
serverConfig.databaseUrl,
|
serverConfig.databaseUrl,
|
||||||
serverConfig.databaseUsername,
|
serverConfig.databaseUsername,
|
||||||
serverConfig.databasePassword,
|
serverConfig.databasePassword,
|
||||||
|
serverConfig.useHikariConnectionPool,
|
||||||
) { vargs ->
|
) { vargs ->
|
||||||
DatabaseSettings(
|
DatabaseSettings(
|
||||||
vargs[0] as DatabaseType,
|
vargs[0] as DatabaseType,
|
||||||
vargs[1] as String,
|
vargs[1] as String,
|
||||||
vargs[2] as String,
|
vargs[2] as String,
|
||||||
vargs[3] as String,
|
vargs[3] as String,
|
||||||
|
vargs[4] as Boolean,
|
||||||
)
|
)
|
||||||
}.distinctUntilChanged(),
|
}.distinctUntilChanged(),
|
||||||
{ (databaseType, databaseUrl, databaseUsername, _) ->
|
{ (databaseType, databaseUrl, databaseUsername, _, hikariCp) ->
|
||||||
logger.info {
|
logger.info {
|
||||||
"Database changed - type=$databaseType url=$databaseUrl, username=$databaseUsername, password=[REDACTED]"
|
"Database changed - type=$databaseType url=$databaseUrl, username=$databaseUsername, password=[REDACTED], hikaricp=$hikariCp"
|
||||||
}
|
}
|
||||||
databaseUp()
|
databaseUp()
|
||||||
|
|
||||||
|
|||||||
@@ -95,12 +95,30 @@ object DBManager {
|
|||||||
preserveKeywordCasing = false
|
preserveKeywordCasing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new HikariCP pool
|
return if (serverConfig.useHikariConnectionPool.value) {
|
||||||
hikariDataSource = createHikariDataSource()
|
// Create a new HikariCP pool
|
||||||
|
hikariDataSource = createHikariDataSource()
|
||||||
|
|
||||||
return Database
|
return Database
|
||||||
.connect(hikariDataSource!!, databaseConfig = dbConfig)
|
.connect(hikariDataSource!!, databaseConfig = dbConfig)
|
||||||
.also { db = it }
|
} else {
|
||||||
|
when (serverConfig.databaseType.value) {
|
||||||
|
DatabaseType.POSTGRESQL ->
|
||||||
|
Database.connect(
|
||||||
|
"jdbc:${serverConfig.databaseUrl.value}",
|
||||||
|
"org.postgresql.Driver",
|
||||||
|
user = serverConfig.databaseUsername.value,
|
||||||
|
password = serverConfig.databasePassword.value,
|
||||||
|
databaseConfig = dbConfig,
|
||||||
|
)
|
||||||
|
DatabaseType.H2 ->
|
||||||
|
Database.connect(
|
||||||
|
"jdbc:h2:${Injekt.get<ApplicationDirs>().dataRoot}/database",
|
||||||
|
"org.h2.Driver",
|
||||||
|
databaseConfig = dbConfig,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}.also { db = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shutdown() {
|
fun shutdown() {
|
||||||
|
|||||||
Reference in New Issue
Block a user