Postgresql support added
This commit is contained in:
parent
ba2cb2b578
commit
c915b0b9b1
4 changed files with 66 additions and 5 deletions
|
@ -24,6 +24,7 @@ Available env variables with their default values that you can overwrite:
|
|||
| NEXTCLOUD_DLNA_INTERFACE | eth0 | interface the server will be listening on |
|
||||
| NEXTCLOUD_DLNA_FRIENDLY_NAME | Nextcloud-DLNA | friendly name of the DLNA service |
|
||||
| NEXTCLOUD_DATA_DIR | | nextcloud installation directory (that ends with /data) |
|
||||
| NEXTCLOUD_DB_TYPE | mariadb | nextcloud database type (mysql, mariadb, postgresql) |
|
||||
| NEXTCLOUD_DB_HOST | localhost | nextcloud database host |
|
||||
| NEXTCLOUD_DB_PORT | 3306 | nextcloud database port |
|
||||
| NEXTCLOUD_DB_NAME | nextcloud | nextcloud database name |
|
||||
|
|
|
@ -42,6 +42,7 @@ dependencies {
|
|||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.mariadb.jdbc:mariadb-java-client:3.2.0'
|
||||
implementation 'org.postgresql:postgresql:42.6.0'
|
||||
|
||||
implementation 'org.jupnp:org.jupnp:2.7.1'
|
||||
implementation 'org.jupnp:org.jupnp.support:2.7.1'
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package net.schowek.nextclouddlna.util
|
||||
|
||||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.util.NextcloudDBType.*
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource
|
||||
|
||||
@Configuration
|
||||
@Profile("!integration")
|
||||
@EnableConfigurationProperties(NextcloudDBConfigProperties::class)
|
||||
class DriverManagerDataSourceConfig {
|
||||
@Bean
|
||||
fun driverManagerDataSource(props: NextcloudDBConfigProperties): DriverManagerDataSource {
|
||||
logger.info { "Using Nextcloud DB connection parameters: $props" }
|
||||
return DriverManagerDataSource().also { dataSource ->
|
||||
when (props.type) {
|
||||
MARIADB, MYSQL -> {
|
||||
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
|
||||
dataSource.url = "jdbc:mariadb://${props.host}:${props.port}/${props.name}";
|
||||
}
|
||||
|
||||
POSTGRES -> {
|
||||
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
|
||||
dataSource.url = "jdbc:postgresql://${props.host}:${props.port}/${props.name}";
|
||||
dataSource.connectionProperties?.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect")
|
||||
}
|
||||
|
||||
else -> throw RuntimeException("Unsupported DB type")
|
||||
}
|
||||
dataSource.username = props.user;
|
||||
dataSource.password = props.pass;
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
||||
|
||||
@Profile("!integration")
|
||||
@ConfigurationProperties(prefix = "nextcloud.db")
|
||||
data class NextcloudDBConfigProperties(
|
||||
val type: NextcloudDBType,
|
||||
val host: String,
|
||||
val port: Int,
|
||||
val name: String,
|
||||
val user: String,
|
||||
val pass: String
|
||||
)
|
||||
|
||||
enum class NextcloudDBType(val value: String) {
|
||||
MYSQL("mysql"),
|
||||
MARIADB("mariadb"),
|
||||
POSTGRES("postgres")
|
||||
}
|
|
@ -5,13 +5,15 @@ server:
|
|||
|
||||
nextcloud:
|
||||
filesDir: ${NEXTCLOUD_DATA_DIR}
|
||||
db:
|
||||
type: ${NEXTCLOUD_DB_TYPE:mariadb}
|
||||
host: ${NEXTCLOUD_DB_HOST:localhost}
|
||||
port: ${NEXTCLOUD_DB_PORT:3306}
|
||||
name: ${NEXTCLOUD_DB_NAME:nextcloud}
|
||||
user: ${NEXTCLOUD_DB_USER:nextcloud}
|
||||
pass: ${NEXTCLOUD_DB_PASS:nextcloud}
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
url: "jdbc:mariadb://${NEXTCLOUD_DB_HOST:localhost}:${NEXTCLOUD_DB_PORT:3306}/${NEXTCLOUD_DB_NAME:nextcloud}"
|
||||
username: ${NEXTCLOUD_DB_USER:nextcloud}
|
||||
password: ${NEXTCLOUD_DB_PASS:nextcloud}
|
||||
driver-class-name: org.mariadb.jdbc.Driver
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
|
|
Loading…
Reference in a new issue