-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from Consdata/IKC-353-database-configuration
IKC-353 Database configuration
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
kouncil-backend/src/main/java/com/consdata/kouncil/config/database/FlywayMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} | ||
} |