Skip to content

Commit d27c0aa

Browse files
author
Adrien
committed
feat(dpp): add database provider plugins
1 parent 1274ba8 commit d27c0aa

File tree

14 files changed

+1562
-0
lines changed

14 files changed

+1562
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Check Pull Request for plugin: database provider'
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
paths:
7+
- 'dpp/**'
8+
9+
jobs:
10+
tests:
11+
name: Unit tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up JDK 21 for x64
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '21'
19+
distribution: 'temurin'
20+
architecture: x64
21+
22+
- name: Start PostgreSQL test database
23+
working-directory: dpp/src/test/fake-postgres-db
24+
run: |
25+
docker compose up -d
26+
sleep 5
27+
28+
- name: Install Pandoc
29+
run: sudo apt-get update && sudo apt-get install -y pandoc
30+
31+
- name: Execute unit tests
32+
run: mvn -ntp -pl dpp test
33+
34+
- name: Execute mutation tests
35+
run: mvn -ntp -pl dpp org.pitest:pitest-maven:mutationCoverage
36+
37+
- name: Extract summary from pitest
38+
run: |
39+
echo "<html><head></head><body><h1>Pit Test Coverage Report: database-provider</h1><h3>Project Summary</h3>" > pitest.html
40+
perl -0777 -ne 'print "$1\n" if /(<table>.*?<\/table>)/s' dpp/target/pit-reports/index.html >> pitest.html
41+
echo "</body></html>" >> pitest.html
42+
43+
- name: Convert pitest report to markdown
44+
run: pandoc --from html --to markdown_github --no-highlight pitest.html
45+
46+
- name: Post comment
47+
uses: luukkemp/pr-comment@2024.1
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
with:
51+
path: pitest.html

dpp/README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# 📦 DPP - Database Provider Plugin
2+
3+
The Database Provider Plugin (DPP) is responsible for managing relational database access through configurable datasources within the LinID Identity Manager API ecosystem.
4+
5+
---
6+
7+
## 🚀 Overview
8+
9+
This plugin enables dynamic persistence of entities to PostgreSQL databases using **jOOQ** for SQL construction and execution. It supports configuration-driven entity mapping without requiring static entity definitions, allowing flexible database integration through YAML configuration.
10+
11+
⚠️ **Current Scope**: PostgreSQL only (extensible architecture for future)
12+
13+
---
14+
15+
## 📋 Configuration Model
16+
17+
The plugin integrates with the global YAML configuration:
18+
19+
```yaml
20+
providers:
21+
- name: ExampleDatabase
22+
type: database
23+
url: jdbc:postgresql://DATABASE_HOST:DATABASE_PORT/DATABASE_NAME
24+
username: DATABASE_USER
25+
password: DATABASE_PASSWORD
26+
27+
entities:
28+
- name: account
29+
route: accounts
30+
provider: ExampleDatabase
31+
tasks:
32+
# ... task definitions
33+
access:
34+
create:
35+
table: ACCOUNT_TABLE_NAME
36+
update:
37+
table: ACCOUNT_TABLE_NAME
38+
delete:
39+
table: ACCOUNT_TABLE_NAME
40+
select:
41+
table: ACCOUNT_TABLE_NAME
42+
attributes:
43+
- name: id
44+
type: String
45+
required: false
46+
input: Text
47+
access:
48+
primaryKey: true
49+
column: ID
50+
- name: username
51+
type: String
52+
required: true
53+
input: Text
54+
access:
55+
primaryKey: false
56+
column: USERNAME
57+
```
58+
59+
### Configuration Fields
60+
61+
| Key | Required | Description |
62+
| ------------------------------------------- | -------- | ------------------------------------------------------------------------- |
63+
| `providers[].name` | ✅ | Unique identifier for the database provider |
64+
| `providers[].type` | ✅ | Must be `database` to activate this plugin |
65+
| `providers[].url` | ✅ | JDBC connection URL (PostgreSQL format: `jdbc:postgresql://host:port/db`) |
66+
| `providers[].username` | ✅ | Database authentication username |
67+
| `providers[].password` | ✅ | Database authentication password |
68+
| `entities[].provider` | ✅ | Reference to the database provider name |
69+
| `entities[].access.table` | ✅ | Target database table name for this entity |
70+
| `entities[].attributes[].access.column` | ✅ | Target database column name for this attribute |
71+
| `entities[].attributes[].access.primaryKey` | ✅ | Indicates if this attribute is a primary key |
72+
73+
---
74+
75+
## 🏗️ Architecture
76+
77+
### Connection Pooling
78+
79+
- **Pool Provider**: HikariCP
80+
- **Pool Scope**: One pool per configured database provider
81+
- **Configuration**:
82+
- Maximum pool size
83+
- Idle timeout
84+
- Connection timeout
85+
- Validation query (if needed)
86+
87+
### Dynamic Mapping
88+
89+
1. Entity → Table mapping via `entities[].access.table`
90+
2. Attribute → Column mapping via `entities[].attributes[].access.column`
91+
3. Only declared attributes are persisted
92+
4. No static JPA entities required
93+
94+
### jOOQ Integration
95+
96+
- All queries constructed via `DSLContext`
97+
- Dynamic table/field resolution using `DSL.name(...)`
98+
- Bind parameters for all values
99+
- Type-safe SQL construction
100+
101+
---
102+
103+
## 🛠 Building the Project
104+
105+
To compile and build the plugin:
106+
107+
```bash
108+
mvn clean install
109+
```
110+
111+
---
112+
113+
## 🧪 Running Tests
114+
115+
Run tests using:
116+
117+
```bash
118+
mvn test
119+
```
120+
121+
---
122+
123+
## 📝 Usage
124+
125+
1. **Configure Provider**: Add a provider with `type: database` in your YAML configuration
126+
2. **Define Entity Mapping**: Configure `access.table` and column mappings via `attributes[].access.column`
127+
3. **Provider Type**: The plugin responds to provider type `Database`
128+
129+
Example minimal configuration:
130+
131+
```yaml
132+
providers:
133+
- name: MyPostgres
134+
type: database
135+
url: jdbc:postgresql://localhost:5432/mydb
136+
username: dbuser
137+
password: dbpass
138+
139+
entities:
140+
- name: user
141+
route: users
142+
provider: MyPostgres
143+
access:
144+
table: users
145+
attributes:
146+
- name: id
147+
type: String
148+
access:
149+
column: user_id
150+
```
151+
152+
---

dpp/changelog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Initial plugin structure for Database Provider Plugin (DPP)
13+
14+
### Technical Details
15+
16+
### Planned
17+

dpp/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.github.linagora.linid.im</groupId>
9+
<artifactId>linid-im-api-community-plugins</artifactId>
10+
<version>0.1.0</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>dpp</artifactId>
15+
<version>0.1.0</version>
16+
<name>Database Provider Plugin for linid-im-api</name>
17+
<description>A database provider plugin for handling database operations</description>
18+
<url>https://github.com/linagora/linid-im-api-community-plugins</url>
19+
20+
<licenses>
21+
<license>
22+
<name>GNU Affero General Public License v3.0</name>
23+
<url>https://www.gnu.org/licenses/agpl-3.0.html</url>
24+
<distribution>repo</distribution>
25+
<comments>This project is licensed under the GNU AGPL v3.0</comments>
26+
</license>
27+
</licenses>
28+
29+
<developers>
30+
<developer>
31+
<id>Hamilcar31</id>
32+
<name>Adrien CERE</name>
33+
<email>adrien.cere@gmail.com</email>
34+
</developer>
35+
</developers>
36+
37+
<scm>
38+
<connection>scm:git:git://github.com/linagora/linid-im-api-community-plugins.git</connection>
39+
<developerConnection>scm:git:ssh://git@github.com:linagora/linid-im-api-community-plugins.git</developerConnection>
40+
<url>https://github.com/linagora/linid-im-api-community-plugins</url>
41+
</scm>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.jooq</groupId>
46+
<artifactId>jooq</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>com.zaxxer</groupId>
51+
<artifactId>HikariCP</artifactId>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.postgresql</groupId>
56+
<artifactId>postgresql</artifactId>
57+
<scope>runtime</scope>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.modelmapper</groupId>
62+
<artifactId>modelmapper</artifactId>
63+
<version>3.1.1</version>
64+
</dependency>
65+
</dependencies>
66+
67+
</project>

0 commit comments

Comments
 (0)