Skip to content

Commit

Permalink
Merge pull request #352 from Consdata/IKC-353-database-configuration
Browse files Browse the repository at this point in the history
IKC-353 Database configuration
  • Loading branch information
pbelke authored Sep 8, 2024
2 parents 63d3912 + 0d9f83c commit b16d67b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Logging](configuration/LOGGING.md)
* [Websocket](configuration/WEBSOCKET.md)
* [Custom context path](configuration/CUSTOM_CONTEXT_PATH.md)
* [Database](configuration/DATABASE.md)


* [Features](FEATURES.md)
Expand Down
25 changes: 25 additions & 0 deletions docs/configuration/DATABASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Database configuration

Currently, Kouncil supports two databases:
* PostgreSQL
* H2

If no database is specified with below properties, H2 in-memory database will be used.

### Configuration properties
* `spring.datasource.url` JDBC URL of the database
* `spring.datasource.username` login username of the database
* `spring.datasource.password` login password of the database
* `spring.jpa.hibernate.default_schema` sets default schema

### Example
```yaml
spring:
datasource:
url: jdbc:postgresql://localhost:5432/
username: postgres
password: password
jpa:
hibernate:
default_schema: kouncil
```
26 changes: 25 additions & 1 deletion kouncil-backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>kouncil-backend</artifactId>
Expand All @@ -17,6 +19,8 @@
<springdoc-openapi-ui.version>1.8.0</springdoc-openapi-ui.version>
<swagger-annotations.version>2.2.6</swagger-annotations.version>
<testcontainers.version>1.17.6</testcontainers.version>
<postgresql.version>42.7.3</postgresql.version>
<h2database.version>2.2.224</h2database.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -141,6 +145,26 @@
<version>1.1.9</version>
</dependency>

<!--databases-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2database.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.consdata.kouncil.config.database;

import lombok.RequiredArgsConstructor;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class FlywayMigration {

@Value("${spring.jpa.hibernate.default_schema:#{null}}")
private String defaultSchema;

@Bean
public FlywayMigrationStrategy flywayMigrationStrategy() {
return flyway -> {
flyway = Flyway.configure()
.configuration(flyway.getConfiguration())
.baselineOnMigrate(true)
.defaultSchema(defaultSchema)
.load();

flyway.migrate();
};
}
}

0 comments on commit b16d67b

Please sign in to comment.