Skip to content

Commit dbaff6e

Browse files
author
Rob Tjalma
authored
Merge pull request #141 from com-pas/implement-flyway
Added Flyway for PostgreSQL Implementation
2 parents c8d8849 + 16768ae commit dbaff6e

File tree

32 files changed

+649
-118
lines changed

32 files changed

+649
-118
lines changed

.github/workflows/build-project.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
5353
- name: Build Native with Maven
5454
if: ${{ github.event_name == 'pull_request' }}
55-
run: ./mvnw -s custom_maven_settings.xml -B clean verify -Pnative
55+
run: ./mvnw -s custom_maven_settings.xml -B clean verify -P basex,native
5656
- name: Build with Maven
5757
if: ${{ github.event_name == 'push' }}
58-
run: ./mvnw -s custom_maven_settings.xml -B clean verify
58+
run: ./mvnw -s custom_maven_settings.xml -B clean verify -P basex

.github/workflows/release-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ jobs:
5656
env:
5757
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5858
- name: Deploy with Maven to GitHub Packages and Docker Hub
59-
run: ./mvnw -B -s custom_maven_settings.xml -Prelease,native clean deploy
59+
run: ./mvnw -B -s custom_maven_settings.xml -P basex,release,native clean deploy
6060
env:
6161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/sonarcloud-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5757
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5858
run: |
59-
./mvnw -s custom_maven_settings.xml -B -Psonar \
59+
./mvnw -s custom_maven_settings.xml -B -P basex,sonar \
6060
-Dsonar.projectKey=com-pas_compas-scl-data-service \
6161
-Dsonar.organization=com-pas \
6262
-Dsonar.host.url=https://sonarcloud.io \

README.md

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -21,70 +21,13 @@ to [documentation](doc/compas-scl-data-service.md).
2121

2222
There are currently two database implementations available.
2323

24+
- For more information about the BaseX Implementation go to [BaseX](doc/basex.md). (Profile activated by default.)
2425
- For more information about the PostgreSQL Implementation go to [PostgreSQL](doc/postgresql.md).
2526

26-
## Application depends on a running BaseX instance
27+
> **Note:** When switching between implementation it's a good practise to first execute a maven clean to remove
28+
> old dependencies from the target directory in the app module.
2729
28-
Check [basexhttp on DockerHub](https://hub.docker.com/r/basex/basexhttp/) for a running BaseX docker container.
29-
30-
## Running the application in dev mode
31-
32-
You can run your application in dev mode that enables live coding using:
33-
34-
```shell script
35-
./mvnw package io.quarkus:quarkus-maven-plugin:2.2.3.Final:dev
36-
```
37-
38-
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
39-
40-
## Packaging and running the application
41-
42-
The application can be packaged using:
43-
44-
```shell script
45-
./mvnw package
46-
```
47-
48-
It produces the `quarkus-run.jar` file in the `app/target/quarkus-app/` directory. Be aware that it’s not an _über-jar_ as
49-
the dependencies are copied into the `app/target/quarkus-app/lib/` directory.
50-
51-
If you want to build an _über-jar_, execute the following command:
52-
53-
```shell script
54-
./mvnw package -Dquarkus.package.type=uber-jar
55-
```
56-
57-
The application is now runnable using `java -jar app/target/quarkus-app/quarkus-run.jar`.
58-
59-
## Creating a native executable
60-
61-
You can create a native executable using:
62-
63-
```shell script
64-
./mvnw package -Pnative
65-
```
66-
67-
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
68-
69-
```shell script
70-
./mvnw package -Pnative -Dquarkus.native.container-build=true
71-
```
72-
73-
You can then execute your native executable with: `./app/target/code-with-quarkus-local-SNAPSHOT-runner`
74-
75-
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html
76-
.
77-
78-
## Environment variables
79-
80-
Below environment variable(s) can be used to configure the connection to BaseX, if BaseX Server is used.
81-
82-
| Environment variable | Java Property | Description | Example |
83-
| -------------------------------- | ------------------------- | --------------------------------------------- | ---------------- |
84-
| BASEX_HOST | basex.host | Name of the Host where BaseX runs. | localhost |
85-
| BASEX_PORT | basex.port | Port on the Host on which BaseX runs. | 1984 |
86-
| BASEX_USERNAME | basex.username | Username under which the application logs in. | admin |
87-
| BASEX_PASSWORD | basex.password | Password of the username used above. | admin |
30+
## Common Environment variables
8831

8932
Below environment variable(s) can be used to configure which claims and information are used to fill the UserInfo
9033
response.

app/pom.xml

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ SPDX-License-Identifier: Apache-2.0
4141
<groupId>org.lfenergy.compas.scl.data</groupId>
4242
<artifactId>service</artifactId>
4343
</dependency>
44-
<dependency>
45-
<groupId>org.lfenergy.compas.scl.data</groupId>
46-
<artifactId>repository-basex</artifactId>
47-
<scope>runtime</scope>
48-
</dependency>
4944

5045
<dependency>
5146
<groupId>org.lfenergy.compas.core</groupId>
@@ -100,6 +95,11 @@ SPDX-License-Identifier: Apache-2.0
10095
<artifactId>quarkus-junit5-mockito</artifactId>
10196
<scope>test</scope>
10297
</dependency>
98+
<dependency>
99+
<groupId>org.mockito</groupId>
100+
<artifactId>mockito-junit-jupiter</artifactId>
101+
<scope>test</scope>
102+
</dependency>
103103
<dependency>
104104
<groupId>io.rest-assured</groupId>
105105
<artifactId>rest-assured</artifactId>
@@ -139,21 +139,87 @@ SPDX-License-Identifier: Apache-2.0
139139
</execution>
140140
</executions>
141141
</plugin>
142-
143-
<plugin>
144-
<groupId>org.apache.maven.plugins</groupId>
145-
<artifactId>maven-surefire-plugin</artifactId>
146-
<configuration>
147-
<systemPropertyVariables>
148-
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
149-
<maven.home>${maven.home}</maven.home>
150-
</systemPropertyVariables>
151-
</configuration>
152-
</plugin>
153142
</plugins>
154143
</build>
155144

156145
<profiles>
146+
<profile>
147+
<id>basex</id>
148+
149+
<activation>
150+
<activeByDefault>true</activeByDefault>
151+
</activation>
152+
153+
<properties>
154+
<quarkus.profile>prod,prod-basex</quarkus.profile>
155+
</properties>
156+
157+
<dependencies>
158+
<dependency>
159+
<groupId>org.lfenergy.compas.scl.data</groupId>
160+
<artifactId>repository-basex</artifactId>
161+
<scope>runtime</scope>
162+
</dependency>
163+
</dependencies>
164+
165+
<build>
166+
<plugins>
167+
<plugin>
168+
<groupId>org.apache.maven.plugins</groupId>
169+
<artifactId>maven-surefire-plugin</artifactId>
170+
<configuration>
171+
<systemPropertyVariables>
172+
<quarkus.test.profile>test,prod-basex</quarkus.test.profile>
173+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
174+
<maven.home>${maven.home}</maven.home>
175+
</systemPropertyVariables>
176+
</configuration>
177+
</plugin>
178+
</plugins>
179+
</build>
180+
</profile>
181+
182+
<profile>
183+
<id>postgres</id>
184+
185+
<properties>
186+
<quarkus.profile>prod,prod-postgres</quarkus.profile>
187+
</properties>
188+
189+
<dependencies>
190+
<dependency>
191+
<groupId>org.lfenergy.compas.scl.data</groupId>
192+
<artifactId>repository-postgresql</artifactId>
193+
<scope>runtime</scope>
194+
</dependency>
195+
196+
<dependency>
197+
<groupId>io.quarkus</groupId>
198+
<artifactId>quarkus-narayana-jta</artifactId>
199+
</dependency>
200+
<dependency>
201+
<groupId>io.quarkus</groupId>
202+
<artifactId>quarkus-agroal</artifactId>
203+
</dependency>
204+
</dependencies>
205+
206+
<build>
207+
<plugins>
208+
<plugin>
209+
<groupId>org.apache.maven.plugins</groupId>
210+
<artifactId>maven-surefire-plugin</artifactId>
211+
<configuration>
212+
<systemPropertyVariables>
213+
<quarkus.test.profile>test,prod-postgres</quarkus.test.profile>
214+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
215+
<maven.home>${maven.home}</maven.home>
216+
</systemPropertyVariables>
217+
</configuration>
218+
</plugin>
219+
</plugins>
220+
</build>
221+
</profile>
222+
157223
<profile>
158224
<id>native</id>
159225

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
package org.lfenergy.compas.scl.data.rest;
5+
6+
import io.quarkus.runtime.Startup;
7+
import org.lfenergy.compas.scl.data.service.CompasMigratorService;
8+
9+
import javax.annotation.PostConstruct;
10+
import javax.enterprise.context.ApplicationScoped;
11+
import javax.inject.Inject;
12+
13+
@Startup
14+
@ApplicationScoped
15+
public class CompasMigratorStartup {
16+
@Inject
17+
CompasMigratorService compasMigratorService;
18+
19+
@PostConstruct
20+
public void migrate() {
21+
compasMigratorService.migrate();
22+
}
23+
}

app/src/main/resources/application.properties

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@ quarkus.http.limits.max-body-size = 150M
1414
quarkus.log.level = INFO
1515
quarkus.log.category."org.lfenergy.compas.scl.data".level = INFO
1616

17-
# BaseX configuration
18-
basex.host = ${BASEX_HOST:localhost}
19-
basex.port = ${BASEX_PORT:1984}
20-
basex.username = ${BASEX_USERNAME:admin}
21-
basex.password = ${BASEX_PASSWORD:admin}
22-
2317
# Dev Profile overrides.
2418
%dev.quarkus.http.port = 9090
2519
%dev.quarkus.http.cors = true
2620

2721
%dev.quarkus.log.level = DEBUG
2822
%dev.quarkus.log.category."org.lfenergy.compas.scl.data".level = DEBUG
2923

24+
# BaseX configuration
25+
%prod-basex.basex.host = ${BASEX_HOST:localhost}
26+
%prod-basex.basex.port = ${BASEX_PORT:1984}
27+
%prod-basex.basex.username = ${BASEX_USERNAME:admin}
28+
%prod-basex.basex.password = ${BASEX_PASSWORD:admin}
29+
30+
# Datasource configuration for PostgreSQL
31+
%prod-postgres.quarkus.datasource.db-kind = others
32+
%prod-postgres.quarkus.datasource.jdbc.driver = org.postgresql.Driver
33+
%prod-postgres.quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/compas
34+
%prod-postgres.quarkus.datasource.jdbc.max-size = 16
35+
%prod-postgres.quarkus.datasource.username = postgres
36+
%prod-postgres.quarkus.datasource.password = postgres
37+
3038
# Smallrye JWT Properties (Microprofile)
3139
smallrye.jwt.verify.key.location = ${JWT_VERIFY_KEY:http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs}
3240
mp.jwt.verify.issuer = ${JWT_VERIFY_ISSUER:http://localhost:8089/auth/realms/compas}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
package org.lfenergy.compas.scl.data.rest;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.extension.ExtendWith;
8+
import org.lfenergy.compas.scl.data.service.CompasMigratorService;
9+
import org.mockito.InjectMocks;
10+
import org.mockito.Mock;
11+
import org.mockito.junit.jupiter.MockitoExtension;
12+
13+
import static org.mockito.Mockito.*;
14+
15+
@ExtendWith(MockitoExtension.class)
16+
class CompasMigratorStartupTest {
17+
@Mock
18+
private CompasMigratorService compasMigratorService;
19+
20+
@InjectMocks
21+
private CompasMigratorStartup compasMigratorStartup;
22+
23+
@Test
24+
void migrate_WhenCalled_ThenMigratorIsCalled() {
25+
when(compasMigratorService.migrate()).thenReturn(true);
26+
27+
compasMigratorStartup.migrate();
28+
29+
verify(compasMigratorService, times(1)).migrate();
30+
}
31+
}

doc/basex.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2021 Alliander N.V.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
# BaseX Implementation
8+
9+
## BaseX Environment variables
10+
11+
Below environment variable(s) can be used to configure the connection to BaseX, if BaseX Server is used.
12+
13+
| Environment variable | Java Property | Description | Example |
14+
| -------------------------------- | ------------------------- | --------------------------------------------- | ---------------- |
15+
| BASEX_HOST | basex.host | Name of the Host where BaseX runs. | localhost |
16+
| BASEX_PORT | basex.port | Port on the Host on which BaseX runs. | 1984 |
17+
| BASEX_USERNAME | basex.username | Username under which the application logs in. | admin |
18+
| BASEX_PASSWORD | basex.password | Password of the username used above. | admin |
19+
20+
## Development
21+
22+
### Application depends on a running BaseX instance
23+
24+
Check [basexhttp on DockerHub](https://hub.docker.com/r/basex/basexhttp) for a running BaseX docker container. This is
25+
needed when running the SCL Data Service locally. Not needed to run the tests.
26+
27+
```shell
28+
mkdir -p <BASEX-DIR>/data
29+
sudo chown -R 1984:1984 <BASEX-DIR>/data
30+
31+
docker run --rm --name compas_basex \
32+
-p 1984:1984 \
33+
-v <BASEX-DIR>/data:/srv/basex/data \
34+
-d basex/basexhttp:latest
35+
```
36+
37+
> **Note:** Replace <BASEX-DIR> with a directory on your local machine, for instance "~/basex".
38+
> All data will be stored in this directory under "data". This way data isn't lost after stopping the docker container.
39+
40+
### Building the application
41+
42+
You can run the following command to build the BaseX version of the application.
43+
44+
```shell script
45+
./mvnw clean verify
46+
```
47+
48+
### Running the application in dev mode
49+
50+
You can run your application in dev mode that enables live coding using:
51+
52+
```shell script
53+
./mvnw -Dquarkus.profile=dev,prod-basex package io.quarkus:quarkus-maven-plugin::dev
54+
```
55+
56+
### Creating a native executable
57+
58+
You can create a native executable using:
59+
60+
```shell script
61+
./mvnw -P native package
62+
```
63+
64+
This will run the native executable build in a container, because in the native profile the property
65+
"quarkus.native.container-build" is set to 'true'.
66+
67+
You can then execute your native executable with: `./app/target/app-local-SNAPSHOT-runner`
68+
69+
If you want to learn more about building native executables, please see https://quarkus.io/guides/maven-tooling.html.

0 commit comments

Comments
 (0)