Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IKC-353 Database configuration #352

Merged
merged 10 commits into from
Sep 8, 2024
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();
};
}
}
Loading